我的页面没有redirect,因为我的.htaccess文件被设置为:
RewriteEngine on RewriteCond $1 !^(index.PHP|resources|robots.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.PHP/$1 [L,QSA]
我使用这个设置为我的MVC框架,所以我得到的URL /controller/method/argument但是当我redirect到/论坛/ login.PHP裁减/论坛/。
我如何添加这个作为例外,以便我可以redirect到/forum/login.PHP
我发现我的/论坛/目录中的另一个.htaccess可能导致这个问题呢?
.htaccess重写规则删除RK = 0 / RS =后的所有内容
htaccess 301redirect – 删除查询string(QSA)
用连字符replace空格%20和+
htaccessredirect+隐藏在URL中的子文件夹
如何使用.htaccess服务gziped字体? (没有mod gzip或deflate)
# BEGIN PunBB <IfModule mod_rewrite.c> # MultiViews interfers with proper rewriting Options -MultiViews RewriteEngine On # Uncomment and properly set the RewriteBase if the rewrite rules are not working properly #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . rewrite.PHP [L] </IfModule>
.htaccess用get参数重写url
mod_rewrite%{HTTP_USER_AGENT}不等于+或条件(列表)
OpenShift并在.htaccess中redirect
“RewriteEngine不允许在这里”使用XAMPP .htaccess错误
首先我会告诉你如何阅读你的RewriteRule:
RewriteRule ^(.*)$ index.PHP/$1 [L,QSA]
第一个参数是一个正则表达式,可以匹配您请求的URL。 ^(.*)$匹配所有内容,并将这个“everything”存储在稍后可以使用的变量中。
只有在之前有RewriteCond条目时,才会评估它们:
RewriteCond $1 !^(index.PHP|resources|robots.txt)
$1是对RewriteRule第一个圆括号内部匹配的内容的引用。 这与第二个参数比较,这是一个正则表达式,说明几个显式名称,而! 否定表达式,例如这个规则只允许在正则表达式不匹配的情况下执行RewriteRule。 如果这个条件返回true,则会查看下一个条件。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
如果请求的文件名不是真实的目录,这个条件是真的。
只有所有这些条件都是真实的(它们与AND链接在一起),我们才会回到重写规则:
RewriteRule ^(.*)$ index.PHP/$1 [L,QSA]
这个重写步骤的结果被定义为第二个和第三个参数。 与匹配的内容一样, $1被再次使用,并且参数定义如果最初匹配,则该规则将是最后的规则(L),并且在重写目标中定义的任何查询字符串将被附加到任何查询字符串在原始网址(QSA)中。
批判:
MVC框架的通常重写尽可能保持高性能。 您的重写条件都必须进行评估才能成功重写。 只有当RewriteCond返回false时才会停止。 每一个被重写的请求都要经过大量的cpu密集测试。 首先是RewriteRule正则表达式,然后是第一个RewriteCond中的正则表达式,然后是文件系统上的两个硬盘测试用于文件存在。
另一方面,第一个RewriteCond似乎是不必要的。 它测试某些名称,如果找到,则中止重写。 “index.PHP”应该被第二个RewriteCond检测到,因为它是一个现有的文件(如果不是,重写工作将会如何)。 任何以“资源”开头的东西都会被匹配,但可能不应该出于同样的原因:现有资源将被第二个RewriteCond找到。 最后是“robots.txt”文件。 如果你想在机器人抓取你的网站时避免404,那么有一个可能是个好主意。
由于您没有更改查询字符串中的任何内容,因此不需要[QSA]指令。
改进:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [L] RewriteRule ^.*$ index.PHP [L]
第一个RewriteRule将匹配整个请求的路径。 两个RewriteCond与[OR]连接,所以返回true的第一个RewriteCond将取消进一步的评估。 第一个RewriteCond测试是否存在请求的文件。 如果存在,则返回true,处理返回到第一个RewriteRule。 目标表达式是“ – ”,意思是“不要重写”。 [L]停止重写规则的进一步处理。 所以最后,对于现有的文件,我们只有一个正则表达式和一个文件系统测试,然后,这个现有的文件将被发送到浏览器。
如果没有找到文件,第一个RewriteRule和RewriteCond不会被触发,所以[L]不会停止进程。 所以第二个RewriteRule被执行。 这是一个无条件的,正则表达式和以前一样,匹配所有东西,并将其重写为“index.PHP”。
如果有任何文件存在,包括/forum/login.PHP,这个重写将不会调用你的index.PHP。
如果你想继续解析$_SERVER['PATH_INFO']而不是$_SERVER['REQUEST_URI']你可以把第二个改成RewriteRule ^.*$ index.PHP/$0 [L] $_SERVER['REQUEST_URI'] 。
试试这个:
RewriteEngine on RewriteCond $1 !^(index.PHP|forum|resources|robots.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.PHP/$1 [L,QSA]
和这个:
# BEGIN PunBB # ---------------------------------------------------------------------- # Start rewrite engine # ---------------------------------------------------------------------- <Ifmodulee mod_rewrite.c> # MultiViews interfers with proper rewriting Options -MultiViews RewriteEngine On # Uncomment and properly set the RewriteBase if the rewrite rules are not working properly RewriteBase /forum/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . rewrite.PHP [L] </Ifmodulee> # ---------------------------------------------------------------------- # Better website experience for IE users # ---------------------------------------------------------------------- # Force the latest IE version,in varIoUs cases when it may fall back to IE7 mode # github.com/rails/rails/commit/123eb25#commitcomment-118920 # Use ChromeFrame if it's installed for a better experience for the poor IE folk <Ifmodulee mod_setenvif.c> <Ifmodulee mod_headers.c> browserMatch MSIE ie Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie </Ifmodulee> </Ifmodulee> <Ifmodulee mod_headers.c> # Because X-UA-Compatible isn't sent to non-IE (to save header bytes),# We need to inform proxies that content changes based on UA Header append vary User-Agent # Cache control is set only if mod_headers is enabled,so that's unncessary to declare </Ifmodulee> # ---------------------------------------------------------------------- # UTF-8 encoding # ---------------------------------------------------------------------- # Use UTF-8 encoding for anything served text/plain or text/html AddDefaultCharset utf-8 # Force UTF-8 for a number of file formats AddCharset utf-8 .html .css .js .xml .json .RSS # ---------------------------------------------------------------------- # A little more security # ---------------------------------------------------------------------- # Do we want to advertise the exact version number of Apache we're running? # Probably not. ## This can only be enabled if used in httpd.conf - It will not work in .htaccess # serverTokens Prod # "-Indexes" will have Apache block users from browsing folders without a default document # Usually you should leave this activated,because you shouldn't allow everybody to surf through # every folder on your server (which includes rather private places like CMS system folders). <Ifmodulee mod_autoindex.c> Options -Indexes </Ifmodulee> # END PunBB
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。