Ale*_*nch 5 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
Run Code Online (Sandbox Code Playgroud)
至
http://localhost/Project1/index.php
http://localhost/Project1/create/index.php
http://localhost/Project1/create/contact.php
http://localhost/Project1/engage/page1/services.php
Run Code Online (Sandbox Code Playgroud)
分别?
本质上,我需要在URL路径的BEGINNING后面附加“ Project1”(或其他我认为合适的字符串)
谢谢
您可以像这样使用负前瞻:
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]
Run Code Online (Sandbox Code Playgroud)