.htaccess不符合规则
我有以下.htaccess文件.htaccess不符合规则,.htaccess,.htaccess,我有以下.htaccess文件 RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^awesomeslash/ /somepage.php [NC,PT]
RewriteRule ^([^/\.]*)/?([^/\.]*)/?([^/\.]*)/?$ /template2.php?slash1=$1&slash2=$2&slash3=$3 [L]
我遇到了规则问题:
RewriteRule ^awesomeslash/ /somepage.php [NC,PT]
当我去
它没有加载somepage.php,而是跟随它下面的运行,进入template2.php您必须在匹配条件的末尾添加一个
$
,并添加L
标志,如下所示:
RewriteRule ^awesomeslash/$ /somepage.php [L,NC,PT]
我认为在[NC,PT]中添加L应该可以解决这个问题 [L]标志导致mod_rewrite停止处理规则集。在大多数上下文中,这意味着如果规则匹配,将不会处理进一步的规则。这对应于Perl中的最后一个命令,或C中的break命令。使用此标志指示应立即应用当前规则,而不考虑进一步的规则
首先:如果您想将
/awesomeslash/
重写为/somepage.php
,这没有多大意义:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^awesomeslash/ /somepage.php [NC,PT]
RewriteRule ^([^/\.]*)/?([^/\.]*)/?([^/\.]*)/?$ /template2.php?slash1=$1&slash2=$2&slash3=$3 [L]
我想你想要这个:
RewriteRule ^awesomeslash/ /somepage.php [NC,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^([^/\.]*)/?([^/\.]*)/?([^/\.]*)/?$ /template2.php?slash1=$1&slash2=$2&slash3=$3 [L]
其次:
- 在
旁边需要[NC,PT]
标志:L
——这将告诉Apache不要处理其他规则[NC,PT,L]
- 您还需要在匹配模式的末尾添加
,使规则仅匹配此URL,而不匹配$
/awesomeslash/something
RewriteRule^awesomeslash/$/somepage.php[NC,PT,L]