Using mod_rewrite and mod_alias (redirect 301) together in .htaccess?

邮差的信 提交于 2019-11-30 13:47:17
Nick Evans

I found the answer in a great explanation of mod_rewrite and mod_alias

The problem is that mod_rewrite always occurs before mod_alias, regardless of the order the are placed in .htaccess. This is the reverse of the order required for this situation.

The trick is to use RewriteRule [R=301] instead of redirect 301, and hence use mod_rewrite for everything instead of mixing it with mod_alias.

Full solution is as follows:

RewriteEngine on
RewriteBase /

RewriteRule ^oldpage1.html /newpage1.php [R=301,L]
RewriteRule ^oldpage2.php /newpage2.php [R=301,L]
RewriteRule ^oldpage3.php /newpage3.php [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!