Reputation: 189
I need to redirect .php page to .html. My url is like http://localhost/lions/contacts.php
and I need to rewrite like http://localhost/lions/contacts.html
using htaccess.
Till Now I've used following code:
RewriteRule . %1.html [R=301,L]
RewriteRule ^([^./]+)\.html$ index.php
But its not working. Please help thanks.
My Complete htaccess file looks like
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /lions/
#redirect localhost/lions/page.php?page_id=1&album_id=1&action=contacts to localhost/lions/1/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2/%3.html? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ page.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]
#redirect localhost/lions/page.php?page_id=1&action=contacts to localhost/lions/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+)\s [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^./]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
#redirect localhost/lions/contacts.php to localhost/lions/contacts.html
RewriteCond %{THE_REQUEST} /(.+?)\.php[\s?] [NC]
RewriteRule ^ %1.html [R=302,L,NE]
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L]
Upvotes: 1
Views: 801
Reputation: 786349
You can use this code in your /lions/.htaccess
file:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /lions/
#redirect localhost/lions/page.php?page_id=1&album_id=1&action=contacts to localhost/lions/1/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . /%1/%2/%3.html? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ page.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]
#redirect localhost/lions/page.php?page_id=1&action=contacts to localhost/lions/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+)\s [NC]
RewriteRule . /%1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^./]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
#redirect localhost/lions/contacts.php to localhost/lions/contacts.html
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
RewriteRule !^admin/ /%1.html [NC,R=302,L,NE]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
Upvotes: 1