开发者

How to use .htaccess to redirect a url which has a # character

I've been looking at this for a couple of days, even had the IT guys at work try and figure it out but we didn't get very far.

I have a url my.website.com/index.php#!lightBox[gallery]/0/ which I want to redirect to just my.website.com. I can do it fine with just the index.php, but it's the extra parts that aren't working. I've tried:

RewriteCond %{HTTP_HOST} ^my.website.com$ [NC]
RewriteRule (.*) http://my.website.c开发者_开发百科om/index.php#!lightBox[gallery]/0/? [R=301,L]

and cpanel generated the following redirect:

RewriteCond %{HTTP_HOST} ^my.website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.my.website.com$
RewriteRule ^/?$ "http\:\/\/my\.website\.com\/\#\!lightBox\[gallery\]\/0\/" [R=301,L]

Both output my.website.com/%23!lightBox[gallery]/0/ as the url - as you can see the hash isn't being processed.

If anyone has any ideas I'd love to hear!

Thanks :)


Have your rules like this:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com$ [NC]
RewriteRule ^/?$ http://my.website.com/index.php#!lightBox[gallery]/0/ [R=301,L,NE]

You do need to escape dot . in RewriteCond but don't need to escape any special characters on RHS. Importantly you need to have flag NE to not to escape the resulting URI.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜