开发者

htaccess rewrite rules for directories

开发者 https://www.devze.com 2023-04-05 12:27 出处:网络
I am having trouble with some rewrite rules on an updated site...I am trying to redirect requests for old directories to new pages, like this:

I am having trouble with some rewrite rules on an updated site...I am trying to redirect requests for old directories to new pages, like this:

http://www.mysite.com/olddirectory --> http://www.mysite.com/this-is-the-new-page

the following rule work开发者_如何学Pythons, but not with a trailing slash on the directory: ie: /olddirectory redirects correctly, but /olddirectory/ doesn't

RewriteRule ^olddirectory$ this-is-the-new-page [R=301,NC,L]

Any ideas on how to get it to recognise the trailing slash on the dir?


The following rule will do redirect with or without trailing slash:

RewriteRule ^olddirectory/?$ /this-is-the-new-page [NC,R=301,L]

The key is to make trailing slash optional, and that's what ? does: /?

0

精彩评论

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