Search code examples
regexapache.htaccessmod-rewritesubdirectory

.htaccess URL rewrite (remove folder from URL)


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!

Solution

  • 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/