本文介绍了追加路径的目录给url使用htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能获得Apache重定向
how could i get Apache to redirect
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路径的开头
Essentially I need to append "Project1" (or whatever other string I see fit) to the BEGINNING of the url path
感谢
推荐答案
您可以使用负向前查找这样的:
You can use negative lookahead like this:
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]
这篇关于追加路径的目录给url使用htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!