views:

28

answers:

1

Hi,

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.

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

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.

A: 

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.

Felix Kling