开发者

Redirect 301 / Rewrite conundrum

开发者 https://www.devze.com 2023-03-14 02:29 出处:网络
On my site, users can add various URL\'s that need to be redirected. For example; from this: domain.com/oldpage/36/

On my site, users can add various URL's that need to be redirected.

For example; from this: domain.com/oldpage/36/

To this: domain.com/newpage/47/

They are added to the .htaccess like this:

Redirect 301 /oldpage/36/ /new-page/47/

But when accessing the old page they get this:

domain.com/newpage/47/?pid=36&pagename=oldpage

I'm pretty sure t开发者_JAVA百科hese rewrite rules are causing this predicament:

RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3

However, mod_rewrite stuff is not my strongpoint, so I have no idea how to fix it.

Any ideas ?


Adding a ? makes the Rewrite not add the query string to the url.

so this should work:

Redirect 301 /oldpage/36/ /new-page/47/?

As a precaution you could also add it to the end of:

RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1?
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3?

But only if they are needed


Since you are already using mod_rewrite anyway, I suppose you should make your redirects using rewrites too

RewriteRule /oldpage/36/ /new-page/47/ [R=301]

This will "rewrite" the URL from old to new, and will redirect the browser to new url with status code 301. [R] directive means redirect, which also stops other rules from processing, hence the other rules will be handled only when the new request is sent from broswer with new url.

0

精彩评论

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