htaccess hide directory from all url's in website

孤街浪徒 提交于 2019-12-11 13:53:18

问题


I have tried everything from forums but no result. How can I hide directory "example" from all url's in website. For example when user enters:

www.domain.com/example/en/file.php or 
www.domain.com/example/ru/file.php or 
www.domain.com/example/de/file.php

I want him to see in the url only:

www.domain.com/en/file.php or 
www.domain.com/ru/file.php or 
www.domain.com/de/file.php 

but conent have to be taken from

www.domain.com/example/en/file.php or 
www.domain.com/example/ru/file.php or 
www.domain.com/example/de/file.php 

My current htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
#RewriteCond %{THE_REQUEST} /example/ [NC]
#RewriteRule ^example/(.*)$ /$1 [L,R=301,NC,NE]
#RewriteRule ^((?!example/).*)$ /example/$1 [L,NC]

NOTE: it can be more directories in "example" than en, ru or de.


回答1:


put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} /example/ [NC]
RewriteRule ^example/(.*)$ /$1 [L,R=301,NC,NE]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond $1 !js [NC]
RewriteRule ^((?!example/)[a-z]{2}/.*)$ /example/$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^.]+)/?$ $1.php [NC,L]


来源:https://stackoverflow.com/questions/23430099/htaccess-hide-directory-from-all-urls-in-website

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