开发者

mod_rewrite from a subfolder with a querystring to a folder or file

开发者 https://www.devze.com 2023-04-09 08:31 出处:网络
开发者_StackOverflow社区I am trying to redirect from: http://www.example.com/folder/product.aspx?prodid=146
开发者_StackOverflow社区

I am trying to redirect from:

http://www.example.com/folder/product.aspx?prodid=146

to

http://www.example.com/folder2/folder3/

The folders referred to here don't really exist. There are other rewrite rules in place which redirect transparently to the actual content.

If I create a directory called 'folder', and put an .htaccess file in it, I can get the redirect working, BUT, other URLs which refer to that folder no longer work. So I have to try and do the redirect from the .htaccess file in the ROOT folder.

I tried this:

RewriteCond %{QUERY_STRING} prodid=146
RewriteRule ^/folder/product.aspx$ /folder2/folder3/? [R]

...but it doesn't work (I get a 404 error). Using identical syntax but omitting the /folder/ from the 2nd line works if the .htaccess is in the folder directory (so I know the above can't be too far off) - but as I said, I cannot do that. I have tried lots of variations but nothing seems to work. Any assistance appreciated.


You need to remove the slash from the start your URL regexp. Like this:

RewriteRule ^folder/product.aspx$ /folder2/folder3/? [R]
0

精彩评论

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

关注公众号