To remove .php extension from URL and replaced with .html
i have wrote:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php $1.html [QSA,L]
This work fine and i the extension changed, but i get this message:
Not Found
The requested URL /**xxxxxx**.html was not found on this server.
To serve .php files as .html you can use this code:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1.html [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
wrong way round? try
RewriteRule ^(.*)\.html $1.php [QSA,L]
Related
I have a small site with about 10 pages.
So I have made it so that the URL structure is rewritten via .htaccess simply: www.domain.com/name.php becomes www.domain.com/name
The trouble now is that I added some more pages and folder and want it to recognise: www.domain.com/foldername/
However it just cannot manage it. It gives me a 404 page not found as it is searching for www.domain.com/foldername/.php
My .htaccess code is below. Any help would be greatly appreciated!
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com\
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Have your rule check for existence of corresponding .php file before adding .php extension:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
I have my .htaccess set up and it is working great for links like:
http://localhost:8888/z-jquery/view
http://localhost:8888/z-jquery/search
so it is removing .php extension and also redirecting if they are typed in manually which is perfect but I also need my other urls like:
http://localhost:8888/z-jquery/edit?client=dane+kasbo
to be like this if possible:
http://localhost:8888/z-jquery/dane+kasbo
this is my .htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /z-jquery/
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Note: I have searched a lot of .htaccess questions here but none work for me, any help would be much appreciated.
You can use:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /z-jquery/
RewriteCond %{THE_REQUEST} /edit(?:\.php)?\?client=([^&]+)\s [NC]
RewriteRule ^ %1? [R,L,NE]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NE]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^([^/.]+)/?$ edit.php?client=$1 [L,QSA]
I'm using slim framework and it has following .htaccess
Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?url=$1 [NC,L,B,QSA,NE]
</IfModule>
I'm migrating an old site which has urls like index.php?q=about.
Now I want both index.php?q=about and /about/ to go to same page. So I tried this
Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^q=
Rewriterule ^index.php?q=(.*)$ index.php?url=$1 [R=301,NC,B,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?url=$1 [NC,L,B,QSA,NE]
</IfModule>
But I'm getting 404 error. Can anybody help me out?
Update:
mod_rewrite is enabled and /about/ is working fine. I need index.php?q=about to show the same page.
You can use:
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# redirect /index.php?q=about to /about
RewriteCond %{THE_REQUEST} \s/+index\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
I'm using this .htaccess with this inside:
DirectoryIndex index.php index.html
DirectorySlash On
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/(page1|page2|page3)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
#Show every html,htm and xml as php
RewriteRule ^(.*)\.html$ $1.php [nc]
RewriteRule ^(.*)\.htm$ $1.php [nc]
RewriteRule ^(.*)\.xml$ $1.php [nc]
but i did not get to redirect http://example.com/page1 to -> http://example.com/page1/ (and the others page2 and page3 ). since i have test in local my url will be
localhost/example/page1
and should redirect to
localhost/example/page1/
does any one see any problem?
For adding a trailing slash you can have your rules like this:
DirectoryIndex index.php index.html
DirectorySlash On
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1/ [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(page1|page2|page3)$ /$1/ [R=301,L,NC]
#Show every html,htm and xml as php
RewriteRule ^(.+?)\.(?:xml|html?)$ $1.php [NC,L]
I am using a rewrite rule that got off a learning video
but it is not working properly
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I would like it to pick up if just type in
http://www.example.com/hmvctest/helloworld
but it only works if i type in
http://www.example.com/hmvctest/index.php/helloworld
currently only shows "No input file specified" I use codeigniter and cpanel I have tried the two answers below and still no luck my site uses https
Try replacing your rules with this:
Options +FollowSymLinks -Indexes -MultiViews
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(index\.php|images/|robots\.txt) [NC]
RewriteRule ^ index.php%{REQUEST_URI} [L]
Use this code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>