开发者

How to stop strings appending to URL rewrite?

I've implemented a simple .htaccess to rewrite any request on a particular directory.

It works to an extent. If you request with nothing after the trailing slash, then it redirects fine. If you put anything after the trailing slash, it is appended to the end of the URL you're trying to re-direct to.

For example,

  • You request: /dir/
  • You redirect to: /holdingpage.htm

That's fine, however.

Notice the appended index.htm to the end of the URL.

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^185\.132\.
RewriteRule ^(.*)$ http://www.example.com/sub/index_rewrite.shtml$1  [R=302,L] 

Any help, much appreciated.


Well you have $1 at the end of the URL, which means that everything that matches (.*) is appended to the URL. Just leave it:

 RewriteRule     ^(.*)$  http://www.example.com/sub/index_rewrite.shtml  [R=302,L] 

Reference: mod_rewrite

Back-references are identifiers of the form $N (N=0..9), which will be replaced by the contents of the Nth group of the matched Pattern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜