.htaccess URL重写(从URL删除文件夹)

时间:2020-05-20 14:45:03

标签: regex apache .htaccess mod-rewrite subdirectory

尝试使用covid-19 dashboard@anubhava在美国的solution上显示quarantine.country/coronavirus/dashboard/usa/而不是quarantine.country/coronavirus/dashboard/region/usa/

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /coronavirus/dashboard/

RewriteRule ^region/(.*)$ /$1 [L,NC,R]
  • 请让我知道为什么上面的解决方案似乎需要重写。谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在/coronavirus/dashboard/.htaccess中使用以下规则:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /coronavirus/dashboard/

RewriteRule ^(?!region/).*$ region/$0 [L,NC]

这将使您将URL用作: https://quarantine.country/coronavirus/dashboard/usa/