【问题标题】:Redirect all pages to a subpage but ignore specific pages将所有页面重定向到子页面但忽略特定页面
【发布时间】:2013-12-05 20:28:21
【问题描述】:

我需要将域的所有页面重定向到名为“紧急”的子页面。

但是忽略两个特定页面——“紧急”页面本身和另一个称为“系统”的页面。

我目前有:

    AcceptPathInfo On

    Options -Indexes

    
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
    RewriteCond %{REQUEST_URI} !^/(emergency|system)/?$ [NC]
    RewriteRule ^ /emergency? [L,R=301]

    RewriteCond $1 !^(index\.php|assets|robots\.txt|cgi-bin|favicon\.ico)
    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]
    

不起作用

我已经看过了,但也没有任何效果:

任何帮助将不胜感激!

谢谢!

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    ^ 后面有一个斜杠

    试试这个规则:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
    RewriteCond %{REQUEST_URI} !^/(emergency|system)/?$ [NC]
    RewriteRule ^ /emergency? [L,R=301]
    

    您的完整和更正后的 .htaccess

    AcceptPathInfo On
    
    Options -Indexes
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
    RewriteCond %{REQUEST_URI} !^/(index\.php|emergency|system)/?$ [NC]
    RewriteRule ^.+$ /emergency? [L,R=301]
    
    RewriteCond $1 !^(index\.php|assets|robots\.txt|cgi-bin|favicon\.ico)
    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]
    

    【讨论】:

    • 我现在被重定向到 domain.com/emergency 但我得到:“这个网页有一个重定向循环”
    • 你还有其他规则吗?发布您的完整 .htaccess
    • RewriteEngine On RewriteBase / RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111 RewriteCond %{REQUEST_URI} !^/(emergency|system)/?$ [NC] RewriteRule ^ /emergency? [L,R=301] AcceptPathInfo On Options -Indexes <IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymLinks RewriteCond $1 !^(index\.php|assets|robots\.txt|cgi-bin|favicon\.ico) 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>
    • 我现在在手机上。请编辑问题并在此处提供此代码,因为从 cmets 读取它非常困难。
    • 是的。 domain.com/emergency
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2016-07-20
    相关资源
    最近更新 更多