【问题标题】:Add Virtual Folder to all urls (Apache)将虚拟文件夹添加到所有 url (Apache)
【发布时间】:2015-12-18 23:02:21
【问题描述】:

使用 Apache 和 .htaccess 如何执行以下操作:

重定向所有 url 以包含虚假文件夹。 例如:

http://example.com/
http://example.com/example.php
http://example.com/folder/example.php

重定向到:

http://example.com/fakefolder/
http://example.com/fakefolder/example.php
http://example.com/fakefolder/folder/example.php

fakefolder 实际上并不存在于服务器目录中,所以我还需要将http://example.com/fakefolder/ 指向http://example.com/

所以基本上如果用户转到http://example.com/,我希望网址显示http://example.com/fakefolder/,但同时仍指向http://example.com

【问题讨论】:

    标签: regex apache .htaccess url mod-rewrite


    【解决方案1】:

    你可以在你的htaccess中使用:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} !\s/+fakefolder/ [NC]
    RewriteRule ^ /fakefolder%{REQUEST_URI} [R=301,NE,L] 
    
    RewriteRule ^fakefolder(/.*)$ $1 [NC,L] 
    

    【讨论】:

    • 为 croises 的回答竖起大拇指!
    猜你喜欢
    • 2011-05-20
    • 1970-01-01
    • 2011-01-20
    • 2012-09-04
    • 2021-04-11
    • 2014-04-08
    • 2012-03-19
    • 1970-01-01
    • 2019-10-13
    相关资源
    最近更新 更多