【发布时间】:2021-06-12 14:35:28
【问题描述】:
在我主机的根文件夹中,我有一个 htaccess 文件,其中包含以下重定向到 https 和 www 的代码:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
在 /news/ 文件夹中,我有 entry.php 文件,例如 ?slug=this-is-first-entry。我希望它看起来像这样https://www.example.com/news/this-is-first-entry。
所以我想将这个https://www.example.com/news/entry.php?slug=this-is-first-entry 重定向到这个https://www.example.com/news/this-is-first-entry
我在 /news/ 文件夹的 .htaccess 中有这段代码:
RewriteRule ^([^/\.]+)$ entry.php?slug=$1 [NC,L]
它工作正常,但从根文件夹重定向 https 和 www 不起作用。请帮忙,我不熟悉 htaccess。
【问题讨论】:
标签: .htaccess url mod-rewrite url-rewriting friendly-url