当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess - htaccess redirecting from rewritten dynamic urls to new dynamic urls

问题描述:

i am experiencing a very unique problem and i hope someone can help!

so we have recently created a new ecommerce website and we made it live and everything was working great but when we to implement our 301's from our old pages we were getting some wierd things

so the code below actually works

Redirect 301 /directory/ http://mysite.com/index.php?cat=1

this code does not

Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2

the output when i try to do this redirection is "Invalid parameters specified!" on a blank webpage and in the address bar it has this

http://mysite.com/index.php?cat=1/sub_directory/

we were thinking that maybe the problem is because our old pages were dynamic but mod_rewrite was used to create more readable urls and we have also deleted all our old files because they were interfering with our new pages rendering

any help would be greatly appreciated!

thanks

网友答案:

That is strange, as redirect should only match the specific url listed, where as it looks like its behaving like rewriterule and partially matching the subdirectory url against the first rule..

try putting the more specific rule above the less specific, like so:

Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
Redirect 301 /directory/ http://mysite.com/index.php?cat=1

That way the more specific rule will be hit first, and the /directory/ only rule will only match if more specific matches above fail

alternatively, you could try RewriteRules:

RewriteRule ^directory/$ http://mysite.com/index.php?cat=1 [R=301,NC,L]
RewriteRule ^directory/sub_directory/$ http://mysite.com/index.php?cat=2 [R=301,NC,L]

the ^ and $ anchors should prevent any unwanted partial matching

分享给朋友:
您可能感兴趣的文章:
随机阅读: