使用htaccess将路径目录附加到url

时间:2012-02-21 14:46:33

标签: regex apache .htaccess mod-rewrite

我怎样才能让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路径的BEGINNING

谢谢

1 个答案:

答案 0 :(得分:2)

你可以使用这样的负向前瞻:

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]