简体   繁体   English

htaccess 隐藏网站中所有 url 的目录

[英]htaccess hide directory from all url's in website

I have tried everything from forums but no result.我已经尝试了论坛中的所有内容,但没有结果。 How can I hide directory "example" from all url's in website.如何从网站中的所有 url 中隐藏目录“example”。 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:我目前的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.注意: “example”中的目录可以多于 en、ru 或 de。

put this code in your DOCUMENT_ROOT/.htaccess file:将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

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

# add www to host name
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# other than /js/ internally prefix /example/ before all URIs
RewriteCond $1 !js [NC]
RewriteRule ^((?!example/)[a-z]{2}/.*)$ /example/$1 [L,NC]

# if a matching .php file is found add .php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]

你可以把这条线

Options -Indexes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM