【问题标题】:.htaccess URL rewrite (remove folder from URL).htaccess URL 重写(从 URL 中删除文件夹)
【发布时间】:2020-09-06 23:48:09
【问题描述】:

尝试使用@anubhavasolution 在我们的covid-19 dashboard 中显示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]
  • 请告诉我为什么上面的解决方案似乎没有所需的重写。谢谢!

【问题讨论】:

  • 我的 URL 类似于 https://www.test.com/something/en/home。我的代码在目录something 中,但我需要从 URL 中删除它。所以 URL 应该是https://www.test.com/en/home。我用RewriteBase / 尝试了上述规则,但它不起作用@yatko

标签: regex apache .htaccess mod-rewrite subdirectory


【解决方案1】:

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

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

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

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

【讨论】:

  • 我有我的 URL https://www.test.com/something/en/home。我的代码在目录something 中,但我需要从 URL 中删除它。所以 URL 应该是https://www.test.com/en/home。我用RewriteBase / 尝试了上述规则,但它不起作用@anubhava
  • 请打开一个新问题,然后我可能会更好地理解它以帮助您
猜你喜欢
  • 1970-01-01
  • 2018-05-25
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-23
  • 2015-07-27
  • 1970-01-01
相关资源
最近更新 更多