【发布时间】:2018-12-07 19:49:58
【问题描述】:
我希望将example.com/subdir 重定向到example.com?page=subdir,同时仍将example.com/subdir 保留在URL 中。这样,我可以使用不同的获取请求动态地“创建页面”。我已经知道如何做到这一点,但我似乎无法弄清楚如何防止example.com/subdir/subdir 导致资产加载不正确。这是我当前的代码:
Options +FollowSymLinks
RewriteEngine on
# Redirect /page.php, /page.html, and /page.htm to /page
RewriteRule ^(.+)\.(php|html|htm)\/*$ /$1 [R,L]
# If the page is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d
# Internally redirect /page to /index.php?page=page
RewriteRule ^(.*?)/?$ /index.php?page=$1 [NC,END]
# Redirect /index to /
Redirect /index /
【问题讨论】: