regex - .htaccess URL 重写(从 URL 中删除文件夹)
问题描述
尝试使用@anubhava的解决方案quarantine.country/coronavirus/dashboard/usa/
而不是quarantine.country/coronavirus/dashboard/region/usa/
在我们的covid-19 仪表板上显示:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /coronavirus/dashboard/
RewriteRule ^region/(.*)$ /$1 [L,NC,R]
- 请让我知道为什么上面的解决方案似乎没有所需的重写。谢谢!
解决方案
您可以在以下情况下使用这些规则/coronavirus/dashboard/.htaccess
:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /coronavirus/dashboard/
RewriteRule ^(?!region/).*$ region/$0 [L,NC]
这将允许您将 URL 用作:
https://quarantine.country/coronavirus/dashboard/usa/