gpt4 book ai didi

apache - 使用 .htaccess [#Q1.] 修改 URL

转载 作者:行者123 更新时间:2023-12-04 19:07:13 27 4
gpt4 key购买 nike

我想使用 .htaccess 修改我服务器上的 URL但我面临一些问题。
结帐#Q2. here .
规则 #1:

https://example.com/site/index.php

https://example.com/site/

should get converted to short url.

https://example.com/


规则 #2:

https://example.com/

should load full url without expanding.

https://example.com/site/index.php.


规则#3:

https://example.com/a/site/index.php

https://example.com/b/site/index.php

https://example.com/a/site/

https://example.com/b/site/

should get converted to short url.

https://example.com/a/

https://example.com/b/


请注意:我想删除 site来自 URL 的文件夹,我不知道要写 .htaccess , 任何帮助将非常感激。

最佳答案

您可以在站点根目录 .htaccess 中尝试这些规则(假设 sib 目录中没有其他 .htaccess):

RewriteEngine On

# matches /site/ or /site/index.php or
# /a/site/index.php or /b/site/index.php
# captures a/ or b/ or an empty string in %1
# redirects to /a/ or /b/ or /
RewriteCond %{THE_REQUEST} \s/+([ab]/|)site/(?:index\.php)?[?\s] [NC]
RewriteRule ^ /%1 [L,R=302,NE]

# matches a/ or b/ or empty (landing page)
# rewrites to a/site/index.php or b/site/index.php or site/index.php
RewriteRule ^([ab]/)?$ $1site/index.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

关于apache - 使用 .htaccess [#Q1.] 修改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66107862/

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