.htaccess URL rewrite (remove folder from URL)

喜你入骨 提交于 2020-06-28 05:48:06

问题


Trying to show quarantine.country/coronavirus/dashboard/usa/ instead of quarantine.country/coronavirus/dashboard/region/usa/ at our covid-19 dashboard for US, using @anubhava's solution:

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

RewriteRule ^region/(.*)$ /$1 [L,NC,R]
  • please let me know why the solution above doesn's seem to have the desired rewrite. Thank you!

回答1:


You may use these rules in /coronavirus/dashboard/.htaccess:

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

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

This will let you use URL as: https://quarantine.country/coronavirus/dashboard/usa/



来源:https://stackoverflow.com/questions/61916016/htaccess-url-rewrite-remove-folder-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!