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
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.