简体   繁体   中英

pages with .php extension redirect to .html

I m trying to redirect all pages with extension .php to .html with the following code:

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]

RewriteRule ^([^\.]+)\.html$ /rules/$1.php [NC,L]

but got an error "This webpage has a redirect loop"

You have done first redirection of .php to .html and after that you doing .html to .php redirect so, that will recursion of redirection.

make code like this. that will redirect .php to .html files.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.php$ /rules/$1.html [R=301,L]

Replace your code with this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1.html? [R=301,L]

# To internally forward /dir/foo.html to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)\.html?$ /$1.php [L,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM