htaccess隐藏网站中所有URL的目录 [英] htaccess hide directory from all url's in website

查看:302
本文介绍了htaccess隐藏网站中所有URL的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了论坛中的所有内容,但没有结果。
如何隐藏网站中所有网址的目录 example。
例如,当用户输入以下内容时:

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 

,但必须从

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

我当前的htaccess:

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]

注意:

推荐答案

将此代码放入您的 DOCUMENT_ROOT中/.htaccess 文件:

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]

这篇关于htaccess隐藏网站中所有URL的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆