为了账号安全,请及时绑定邮箱和手机立即绑定

.htaccess 重写漂亮的 URL 而不影响默认页面

.htaccess 重写漂亮的 URL 而不影响默认页面

PHP
aluckdog 2023-04-28 15:20:18
我有一个加载www.example.com默认index.php page. 我也有一个login.php,我已经为它设置了这个重写规则。一切正常,但是当我尝试访问它时,www.example.com它会将我重定向到login.php.我想在不影响默认页面的情况下保留规则。请看下面。如果有人有任何想法那就太好了。# ensure permalink when url rewriting was enabled (login.php?r=content/perma&id=6 => /content/perma/?id=6RewriteCond %{QUERY_STRING} ^r=content(/|%2)perma&id=([0-9]*)$RewriteRule ^login\.php$ %{REQUEST_URI}/content/perma/?id=%2 [R=302,L]RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$RewriteRule ^(.*) - [E=BASE:%1]# Sets the HTTP_AUTHORIZATION header removed by apacheRewriteCond %{HTTP:Authorization} .RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]RewriteCond %{REQUEST_FILENAME} -fRewriteRule .? - [L]RewriteRule .? %{ENV:BASE}/login.php [L]
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

您可以在站点根目录 .htaccess 中使用此代码:


# ensure permalink when url rewriting was enabled 

# (login.php?r=content/perma&id=6 => /content/perma/?id=6


RewriteEngine On


RewriteCond %{QUERY_STRING} ^r=content(/|%2)perma&id=([0-9]*)$

RewriteRule ^login\.php$ %{REQUEST_URI}/content/perma/?id=%2 [R=302,L]


# Sets the HTTP_AUTHORIZATION header removed by apache

RewriteCond %{HTTP:Authorization} .

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . login.php [L]


查看完整回答
反对 回复 2023-04-28
  • 1 回答
  • 0 关注
  • 93 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信