【问题标题】:htaccess hide directory from all url's in websitehtaccess 隐藏网站中所有 url 的目录
【发布时间】:2014-06-19 06:05:13
【问题描述】:

我已经尝试了论坛中的所有内容,但没有结果。 如何从网站中的所有 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 更多。

【问题讨论】:

    标签: php .htaccess mod-rewrite url-rewriting hide


    【解决方案1】:

    将此代码放入您的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]
    

    【讨论】:

      【解决方案2】:

      你可以把这行写出来

      Options -Indexes
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-25
        • 1970-01-01
        • 2014-07-08
        • 1970-01-01
        • 2014-06-17
        • 2016-05-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多