Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess似乎在最后一个标志之后继续_.htaccess - Fatal编程技术网

.htaccess似乎在最后一个标志之后继续

.htaccess似乎在最后一个标志之后继续,.htaccess,.htaccess,在我制作的小公文包网站中,我希望有干净的URL。为此,我使用了一个.htaccess文件。目前我的网站运行速度为127.0.0.1/网站。我的.htaccess如下所示: RewriteEngine On RewriteBase /website RewriteRule ^about$ index.php?page=0 [L,NC] RewriteRule ^portfolio$ index.php?page=1 [L,NC] RewriteRule ^cv$ index.php?page=

在我制作的小公文包网站中,我希望有干净的URL。为此,我使用了一个.htaccess文件。目前我的网站运行速度为127.0.0.1/网站。我的.htaccess如下所示:

RewriteEngine On

RewriteBase /website

RewriteRule ^about$ index.php?page=0 [L,NC]
RewriteRule ^portfolio$ index.php?page=1 [L,NC]
RewriteRule ^cv$ index.php?page=2 [L,NC]
RewriteRule ^contact$ index.php?page=3 [L,NC]

RewriteRule ^.*$ about [L,R]
如果我删除最后一行,一切正常。我可以转到
127.0.0.1/website/about
,服务器显示
127.0.0.1/website/index.php?page=0
,而url不变。但是,我希望其他每个url都被重定向到
127.0.0.1/website/about
,我尝试在最后一行这样做。但是,如果我现在尝试转到
127.0.0.1/website/anything
,其中anything是任意字符串,它会将我重定向到
127.0.0.1/website/about?page=0
。除此之外,我希望
127.0.0.1/website/about
处理得很好,因为第一个重写规则中有最后一个标志,但这会将我重定向到相同的错误url


我不知道为什么这不起作用,也很困惑,因为在我看来,这似乎是在跳过最后一面旗帜。我希望有人能指出我做错了什么。提前感谢。

最后一条规则重写了所有内容,因此模式必须更加具体

RewriteRule !^index\.php$ about [L,R]
这可能会奏效:

RewriteEngine On

RewriteBase /website

RewriteRule ^about$ index.php?page=0 [L,NC]
RewriteRule ^portfolio$ index.php?page=1 [L,NC]
RewriteRule ^cv$ index.php?page=2 [L,NC]
RewriteRule ^contact$ index.php?page=3 [L,NC]

RewriteCond %{REQUEST_URI}  !^/cv        [NC]
RewriteCond %{REQUEST_URI}  !^/about     [NC]
RewriteCond %{REQUEST_URI}  !^/contact    [NC]
RewriteCond %{REQUEST_URI}  !^/portfolio  [NC]
RewriteRule ^.*$ /about [R,L]

它会将所有非
/cv
/about
/contact
/portfolio
的内容重定向到
/about

,这确实解决了问题。这也帮助我理解了问题所在,尽管你没有详细解释。谢谢你。谢谢你的尝试,但这不起作用。它提供与以前相同的输出。我认为问题在于我的前4条规则更改了index.php?page=num中的url,因此重写条件不再有效。Deadooshkas工作的事实证实了这一点。无论如何,谢谢。为了进一步解释发生了什么,问题是每次输入url实际匹配并被任何规则重写时,引擎都会使用重写的版本启动新一轮,以可能再次重写重写的url。
[L]
标志只允许您打破当前回合。我同意这个方案可能会产生误导,如果你不够小心,你很容易会因为无限循环而导致500个内部服务器错误。非常感谢你的确认。我想这是因为Deadooshkas的答案是有效的。我现在知道如何解决这个问题了。