在我的网络服务器上,我想保留以下文件夹结构,以便更容易维护:
/de/index.html
如何将网页浏览器 www.mydomain.de/de/index.html 中的可见网址更改为 www.mydomain.de/index.html 。 htaccess的?
我想将/ de /目录保留在服务器上,但我不想在浏览器中显示它。 你会提出什么建议?
答案 0 :(得分:2)
这是一个微不足道的重写。
此版本假定您的脚本,图像和CSS文件仍在标记中使用/de/whatever.css结构。
RewriteEngine On
# Don't rewrite requests to /de or other real files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*/(css|scripts)
# Rewrite incoming requests to their equivalent behind /de
RewriteRule ^(.*)$ de/$1 [L,QSA]
此版本允许图像,CSS和脚本也隐藏它们:
RewriteEngine On
# Don't rewrite requests to /de or other real files
RewriteCond %{REQUEST_URI} !^/de/?
# Rewrite incoming requests to their equivalent behind /de
RewriteRule ^(.*)$ de/$1 [L,QSA]
强制将请求重定向到/ de以使用新URL:
RewriteEngine On
# Force redirection out of /de
RewriteCond %{REQUEST_URI} ^/test/de/
RewriteRule test/de/(.*) http://%{HTTP_HOST}/test/$1 [L,R=301,QSA]
# Don't rewrite requests to /de or other real files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*/(css|scripts)
# Rewrite incoming requests to their equivalent behind /de
RewriteRule ^(.*)$ de/$1 [L,QSA]