【问题标题】:Why is my htaccess line being overruled为什么我的 htaccess 行被否决
【发布时间】:2018-05-28 20:25:26
【问题描述】:

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

我在我的网站 url 后只输入 /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

【问题讨论】:

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


    【解决方案1】:

    我认为问题在于您的 cms 规则模式 ^cms/$ 中的斜杠。您的模式与带有斜杠 (/cms/) 的 cms uri 匹配,但无法匹配 /cms (没有斜杠)。

    您的/cms uri 将被重写为catlisting.php?alias=$1,因为最后一条规则有一个包含可选斜杠^([\w-]+)/?$ 的全部模式,它与/cms/cms/ 匹配。

    要解决此问题,您需要从 cms Rewrite 模式中删除斜杠

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

    【讨论】:

    • 这修复了它!谢谢。
    猜你喜欢
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多