【问题标题】:redirect via htaccess where IP is not && remove index.php通过 htaccess 重定向,其中 IP 不是 && 删除 index.php
【发布时间】:2012-11-18 11:02:56
【问题描述】:

我通常使用这个 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 文件将所有到给定 url 的流量引导到另一个

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

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

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

谢谢, 史蒂文

【问题讨论】:

  • 不确定你需要什么,但你说你需要将两者结合起来——那么为什么你不只是在上面的重写中添加REMOTE_ADDR 条件呢?我错过了什么吗?
  • 就是这样,我试过了。我在通常的规则之后添加了我的 {REMOTE_ADDR} 规则,但即使添加了我的 IP 地址,我总是会被重定向。

标签: regex apache .htaccess expressionengine


【解决方案1】:

发现这很好用:

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]

【讨论】:

    猜你喜欢
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2014-08-31
    相关资源
    最近更新 更多