【问题标题】:append path directory to url using htaccess使用 htaccess 将路径目录附加到 url
【发布时间】:2012-02-21 14:46:33
【问题描述】:

我怎样才能让 Apache 重定向

http://localhost/index.php
http://localhost/create/index.php
http://localhost/create/contact.php
http://localhost/engage/page1/services.php

http://localhost/Project1/index.php
http://localhost/Project1/create/index.php
http://localhost/Project1/create/contact.php
http://localhost/Project1/engage/page1/services.php

分别?

基本上我需要将“Project1”(或我认为合适的任何其他字符串)附加到 url 路径的开头

谢谢

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    您可以像这样使用负前瞻:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # redirect to /Project1/ if it is not already /Project1/
    RewriteRule ^((?!Project1/).*)$ Project1//$1 [L,NC]
    

    【讨论】:

      猜你喜欢
      • 2020-06-10
      • 1970-01-01
      • 2011-12-06
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      相关资源
      最近更新 更多