通过htaccess重定向,其中IP不是&&删除index.php

时间:2012-11-18 11:02:56

标签: regex apache .htaccess expressionengine

我通常使用此htaccess文件从ExpressionEngine中的URL中删除index.php

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

AcceptPathInfo On

Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On

Options +FollowSymLinks

# Looks for files and directories that do not exist
# and provide the segments to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>  

虽然效果很好,但在我们将此网站投入生产之前,我们会通过此htaccess文件将所有流量指向给定的网址

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]

我自己的ip地址正在替换localhost调用,以便我可以访问该站点。

基本上我正在寻找的是这些2的组合,它会从我的URL中删除index.php,但仍会重定向其他人。

谢谢, 史蒂芬

1 个答案:

答案 0 :(得分:0)

发现这很有效:

RewriteEngine on

# If your IP address matches any of these - then dont re-write
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 
RewriteRule ^(.*)$ http://www.anothersite.com/ [R=302,L]


# do not rewrite links to the assets and theme files
RewriteCond $1 !^(assets|themes|images)

# do not rewrite for php files in the document root, robots.txt etc
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml)

# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]