我从论坛尝试了一切,但没有结果。我如何隐藏目录"示例"从网站的所有url。例如,当用户输入:
www.domain.com/example/en/file.php or
www.domain.com/example/ru/file.php or
www.domain.com/example/de/file.php
我想让他只在url中看到:
www.domain.com/en/file.php or
www.domain.com/ru/file.php or
www.domain.com/de/file.php
但是内容必须取自
www.domain.com/example/en/file.php or
www.domain.com/example/ru/file.php or
www.domain.com/example/de/file.php
我当前的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]
注意:在"example"中可以包含比en、ru或de更多的目录。
将此代码放入您的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