gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:22:41 24 4
gpt4 key购买 nike

我怎样才能让 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

谢谢

最佳答案

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

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]

关于regex - 使用 htaccess 将路径目录附加到 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com