redirect not working with .htaccess

时间:2015-07-31 20:50:52

标签: regex apache .htaccess mod-rewrite ubuntu-14.04

I have this in my htaccess

Options +FollowSymlinks
RewriteEngine On
Deny from all
#RewriteRule (.*) http://google.com  [R=301,L]
Allow from 127.0.0.1
Allow from 89.32.93.99
RewriteRule index.php$ /otherfolder [R=301,L]

I am trying to redirect all the requests to a new folder but for some reason the above does not work.

I have also tried

Redirect 301 / /otherfolder

but that just added other folder again and again to my domain like this

mydomain.com/otherfolder/otherfolder/.....

thanks

1 个答案:

答案 0 :(得分:1)

保持这样的规则:

Deny from all
Allow from 127.0.0.1
Allow from 89.32.93.99

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(index\.php)?$ /otherfolder [NC,R=301,L]

^(index\.php)?$将匹配网址中的//index.php