htaccess on apache
I have this url:
mydomain.com/old.html
I want it to be rewritten as:
mydomain.com/new.html
But I also want mydomain.com/old.html to always redirect to mydomain.com/new.html .
I tried the following:
RewriteRule ^/new.html /old.html [R=301,L,PT]
But it doesn't work.
Redirect 301 /old.html http://www.yoursite.com/new.html
应该管用。
Remove the leading slash (or make it optional) because it's stripped from URI's when applying rules in an htaccess file:
RewriteRule ^/?new.html /old.html [R=301,L,PT]
This would be required to work in conjunction with other rewrite rules, so that everything happens within one module (mod_rewrite), but if you do not need mod_rewrite, you can rely on mod_alias instead (removing the mod_rewrite redirect):
Redirect 301 /old.html http://www.yoursite.com/new.html
But this will redirect stuff like: /old.html/blahblah
to http://www.yoursite.com/new.html/blahblah
If you don't want that, use:
RedirectMatch 301 ^/old.html$ http://www.yoursite.com/new.html
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.