Question: I'm trying to do a 301 redirect with mod\_rewrite on a PHP script from an upper directory on my website. The URL I want to redirect looks like this (obviously the querystring is always different).

```
http://www.foo.com/bar/script.php?variable1=bar&variable2=foo

```

And I want to redirect script.php? to the lower lever on my site, like this:

```
http://www.foo.com/script.php?variable1=bar&variaable2=foo

```

Can anyone help with this?

Thanks,

Matt

Answer: 
For a vhost config (which i prefer to a htaccess), it would be

```
  RewriteEngine On
  RewriteCond %{REQUEST_URI} ^/bar/script.php
  RewriteRule $ /index.php [R=301,NC]

```

for htaccess it should be

```
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_URI} ^/bar/script.php
  RewriteRule $ /index.php [R=301,NC]

```
You could try something like this:

```
RewriteEngine On
RewriteRule ^bar/script\.php$ http://%{HTTP_HOST}/script.php [QSA,L,R=301]

```