开发者

.htaccess help needed

开发者 https://www.devze.com 2023-02-09 01:29 出处:网络
What is the difference between RedirectPermanent and RewriteRule i came across a code RewriteRule ^coaching/([^/]+)/?$ search_result.php?categoryName=$1[NC,L]

What is the difference between

RedirectPermanent and RewriteRule

i came across a code

RewriteRule ^coaching/([^/]+)/?$ search_result.php?categoryName=$1  [NC,L]

another setting is

RedirectPermanent "/coaching/Run to live"   http://www.example.com/coaching

The former rule breaks my setting i can't remove that too.

It makes the output like this

http://www.example.com/coaching?categoryName=Run%20to%20live

What should be added so that without changing first code i can acheive the result

http开发者_运维百科://www.example.com/coaching


The RewriteRule directive comes from mod_rewrite, whereas the RedirectPermanent directive comes from mod_alias.

In this scenario, they don't play well together. The RedirectPermanent uses the original URL /coaching/Run to live, but sees the modified query string ?categoryName=Run%20to%20live created by your RewriteRule. While this is kind of unexpected, it's a gotcha of using mod_rewrite and mod_alias together in a per-directory (.htaccess) context.

Since you need mod_rewrite for your original RewriteRule anyway, the best option is to use a RewriteRule instead of RedirectPermanent for the second operation too. This would look something like this:

# Perform this redirect first
RewriteRule "^coaching/Run to live$" http://www.example.com/coaching [R=301,L]

RewriteRule ^coaching/([^/]+)/?$ search_result.php?categoryName=$1  [NC,L]


The difference (under certain conditions) is that using RedirectPermanent the HTTP response is 301 (Permanent Redirect) - telling the browser/crawler that the page has moved in a permanent way... RewriteRule returns 302 (unless specified otherwise in the options) - and this means to the browser that this redirection is "temporary" and that at a future date this link will again serve the requested content.

0

精彩评论

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