【问题标题】:Hide folder in URL but not if there is only domain in URL隐藏 URL 中的文件夹,但如果 URL 中只有域,则不隐藏
【发布时间】:2014-04-01 04:43:16
【问题描述】:

我想在我的 URL 中隐藏文件夹“main”。所以如果有这样的文件:

my_domain.com/main/something.php

我明白了:

my_domain.com/something.php

我找到的最佳解决方案是:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+main/([^\s]+) [NC]  
RewriteRule ^ %1 [R=301,L]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule (?!^main/)^(.*)$ /main/$1 [L,NC]

它可以正常工作,但在 URL 中只有“my_domain.com”的情况下就不行了。
然后我得到“您无权访问此服务器上的 /main/”。因为 URL 可能更改为 'my_domain.com/main/'

我怎样才能修改它以使其仅在 URL 中存在不止域的内容时才起作用?

【问题讨论】:

    标签: apache .htaccess url mod-rewrite


    【解决方案1】:

    你可以使用:

    RewriteCond %{THE_REQUEST} \s/+main/([^\s]+) [NC]  
    RewriteRule ^ %1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteRule ^((?!^main/).+)$ /main/$1 [L,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-01
      • 2017-06-06
      • 2020-01-13
      • 2013-01-24
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 2018-04-05
      相关资源
      最近更新 更多