使用.htaccess [#Q1.]修改URL [英] Modify URL with .htaccess [#Q1.]

查看:48
本文介绍了使用.htaccess [#Q1.]修改URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 .htaccess 修改服务器上的URL,但是我遇到了一些问题.

I want to modify the URL on my server using .htaccess but I'm facing some issues.

结帐#Q2.这里.

规则1:

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

https://example.com/site/

应该转换为短网址.

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/

应该转换为短网址.

https://example.com/a/

https://example.com/b/

请注意::我想从URL中删除 site 文件夹,并且我不知道写 .htaccess ,任何帮助都可以非常感谢.

Note that: I want to remove the site folder from URL's and I don't know to write .htaccess, any help would be much appreciated.

推荐答案

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

You may try these rules in your site root .htaccess (assuming there are no other .htaccess in sib directories):

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]

这篇关于使用.htaccess [#Q1.]修改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆