开发者

301 redirect priority order

I am looking to change the extension for all pages from HTML to PHP as I redo a company's website. So I'm adding these lines into the .htaccess file.

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

However, the contact, and about pages were in a folder in the old site that I don't want to put them into on the new site. So 开发者_开发技巧if I put the specific redirects above the generic "HTML-to-PHP" redirect, like this:

redirect 301 /company-information/contact.html http://www.example.com/contact.php

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

Will that redirect the contact page before it even looks at the generic redirect or does it go all the way through the .htaccess file and override whatever went before in the file.

Or am I getting this totally around my head and there's another, much better way of doing it?


As mentioned in the comment from @LazyOne the higher priority rules should go before the lower priority rules in the .htaccess


First, I don't understand why you want to change the suffix of filenames for the clients. It's better & popular to simply remove it.

Second, Apache's Redirect directive tells the client to fetch the resource from another location by sending the HTTP Location header. This is a redundant/useless round-trip.

It's better to use the rewriting rules to provide the user a different content, try:

RewriteCond ${REQUEST_URI} =/company-information/contact.html
RewriteRule ^(.*)$ /contact.php [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜