为什么我的htaccess线被否决了

时间:2018-05-28 10:20:52

标签: .htaccess mod-rewrite server url-rewriting

我有一个具有以下路径的cms:cms / administrator / index.php

我已经将以下行重定向到此,只在我的网站网址后输入/ cms。

#CMS rewrite
RewriteRule ^cms/$ /cms/administrator/index.php [L]

但是这行不会重写到我的cms文件夹中的索引文件,它会重定向到catlisting.php一行,后面添加几行:

RewriteRule ^([\w-]+)/?$ catlisting.php?alias=$1 [QSA,L]

键入时如何使用此规则:website.nl/cms?

这是我的整个htaccess文件:

DirectoryIndex
RewriteEngine  on
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

#Indexes uitzetten
Options -Indexes

#Cross site access toestaan
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"

#Sitename

DirectoryIndex index.php

#CMS rewrite
RewriteRule ^cms/$ /cms/administrator/index.php [L]

RewriteRule         ^home index.php [QSA,L]
RewriteRule         ^overzicht shopping-cart-page.php [QSA,L]
RewriteRule         ^bestellen checkout.php [QSA,L]
RewriteRule         ^contact contact.php [QSA,L]
RewriteRule         ^vragen vragen.php [QSA,L]
RewriteRule         ^status success.php [QSA,L]
RewriteRule         ^voorwaarden voorwaard.php [QSA,L]
RewriteRule         ^info/(.*).html contentlisting.php?alias=$1 [QSA,L]
RewriteRule         ^verhuur/(.*)/ lp.php?alias=$1 [QSA,L]
RewriteRule         ^(.*).html content.php?alias=$1 [QSA,L]
#Zorg ervoor dat onderstaande regels alleen worden uitgevoerd als het geen folder (d) is of een file (f)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#LP
RewriteRule ^c-[^/]+/(.+)$ /verhuur/$1 [L,R=301]
#Shop
RewriteRule ^([\w-]+)/([\w-]+)/?$ product-page.php?cat=$1&alias=$2 [QSA,L]

RewriteRule ^([\w-]+)/?$ catlisting.php?alias=$1 [QSA,L]

#ErrorPages
ErrorDocument 404 /error/404.php
ErrorDocument 403 /error/403.php
ErrorDocument 500 /error/500.php
ErrorDocument 501 /error/501.php
ErrorDocument 503 /error/503.php
ErrorDocument 504 /error/504.php

1 个答案:

答案 0 :(得分:1)

我认为问题是cms规则模式^cms/$中的搜索斜杠。您的模式将cms uri与traling斜杠(/cms/)匹配,并且无法匹配/cms(没有traling斜杠)。

您的/cms uri正在被重写为catlisting.php?alias=$1,因为上一个规则有一个catch all模式,其中包含一个匹配^([\w-]+)/?$和{{1}的可选traling斜杠/cms }。

要解决此问题,您需要从/cms/重写模式中删除traling斜杠

cms