.htaccess add an extra word to add all my URLs

2019-08-09 05:15发布

问题:

I need to a add a extra word right after my domain name to all my website URLs.

Lets say my url is http://www.example.com/somecategory/someproduct.html, it should be http://www.example.com/logado/somecategory/someproduct.html.

Is it possible to do it with .htaccess file ?

If so what should i add to my .htaccess file ?

回答1:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# prefix each URL by /logado/ if it is not present
RewriteCond %{THE_REQUEST} !\s/+logado/ [NC]
RewriteRule ^ logado%{REQUEST_URI} [R=302,L,NE]

# internally remove /logado/ from all URLs
RewriteRule ^logado/(.*)$ $1 [L,NC]