mod_rewrite:无法内部重写为(假的)干净的 URL。

mod_rewrite:无法内部重写为(假的)干净的 URL。

这更像是为什么问题。

我正在使用一个可以通过 mod_rewrite 处理干净 URL 的 CMS。

网站有一个部分/accessories现在必须重命名为/store

在懒惰模式下,我只想使用 mod_rewrite 进行内部重写,因此,当访问时example.com/store/,我希望从 透明地提供内容example.com/accessories,而无需任何外部重定向。

到目前为止,我已经尝试过这个:

RewriteEngine On

# Internally rewrite /store to /accessories
RewriteRule ^store /accessories [L] #also tried with other flags like PT, N, C

# All below rules are provided by CMS
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]

RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php

没什么效果

我能让它发挥作用的仅有的两种方法是:

  • 通过内部将请求重写为其对应的“混乱”的 URL,如下所示:

    RewriteRule ^store /index.php?s=accessories [L]

  • 通过使用 mod_proxy 和ProxyPass指令(我将其作为解决方案丢弃,因为 mod_proxy 在生产服务器上不可用)。

我刚刚得出的结论是,URL 无法在内部重写为其他(假的)干净 URL,同时保持重写链有效。“假”是指不是真实文件系统路径(通常是文件夹)或真实文件(如 index.php)的 URL 路径。

那么,问题是:为什么?

相关内容