htaccess重写url与最终子文件夹



我有这样的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

我似乎不知道该如何处理这种情况。如何解决这个问题?

问题是模式([^/]+)匹配任何东西,但/

像这样使用:

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]

最新更新