htaccess 用最终的子文件夹重写 url

莱里奥·法耶塔

我有这样的网址:

https://mywonderfulsite.com/page

我的 .htaccess 将其重写为

https://mywonderfulsite.com/index.php?source=page

.htaccess 如下:

RewriteEngine on
RewriteBase /
RewriteRule \.(php)$ - [L]
RewriteRule ^index\.html$ - [L]
RewriteRule ^favicon\.ico$ - [L]
RewriteRule ^custom404\.html$ - [L]
RewriteRule ^custom500\.html$ - [L]
RewriteRule ^([^/]+)/?$ index.php?source=$1 [L]

如果 url 包含像这样的子文件夹,这将失败

https://mywonderfuldomain.com/subfolder/anotherpage

那应该变成

https://mywonderfuldomain.com/index.php?source=/subfolder/anotherpage

我似乎不明白如何处理这种情况。如何解决?

阿努巴瓦

问题在于模式([^/]+)匹配除 a 之外的任何内容/

像这样使用它:

RewriteEngine On

RewriteRule \.php$ - [L,NC]

RewriteRule ^(?:favicon\.ico|(?:index|custom500|custom404)\.html)$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?source=$0 [L,QSA]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章