【问题标题】:.htaccess sub links not effecting.htaccess 子链接不影响
【发布时间】:2020-07-19 18:52:45
【问题描述】:

我想创建到 seo 友好链接的动态链接,所以我创建了一个 htaccess 规则如下

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/category/([a-z0-9_-]+)?$  products.php?category=$1  [NC,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^products/uicat/([a-z0-9_-]+)?$  products.php?uicat=$1  [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (index|about|products) $1.php [L]  

我正在使用 apache 和 PHP 7.3 运行 centos 7,并且我已启用 Allowoverride ALL 和选项:

Options Indexes FollowSymLinks ExecCGI Includes MultiViews

如果我将重写规则重命名为

RewriteRule ^testproducts/uicat/([a-z0-9_-]+)?$  products.php?uicat=$1  [NC,L]

它确实有效,所以我不知道我做错了什么,而且我对这些 htaccess 规则不太满意,所以所有帮助表示赞赏。

【问题讨论】:

    标签: php apache .htaccess centos7


    【解决方案1】:
    Options Indexes FollowSymLinks ExecCGI Includes MultiViews
    

    您需要从 Options 指令中删除 MultiViews

    通过启用MultiViews mod_negotiation 将触发products.php 的内部子请求(已请求/products) - 在您的 mod_rewrite 指令能够处理请求之前,因此不会包含 URL 参数。

    您可能还想删除Indexes。你真的需要ExecCGIIncludes吗?


    旁白:

    您需要所有文件系统检查吗? /products/category/something 形式的请求可以映射到文件或目录吗?请记住,您的正则表达式已经排除了文件扩展名。

    RewriteRule (index|about|products) $1.php [L]
    

    这与请求的 URL 路径中的 indexaboutproductsanywhere 匹配 - 这太笼统了,因为您正在重写当前目录中的文件。

    【讨论】:

      猜你喜欢
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 2014-06-17
      • 2015-04-06
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多