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

我有一个加载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=6


RewriteCond %{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 apache

RewriteCond %{HTTP:Authorization} .

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


RewriteCond %{REQUEST_FILENAME} -f

RewriteRule .? - [L]


RewriteRule .? %{ENV:BASE}/login.php [L]


aluckdog
浏览 94回答 1
1回答

慕码人8056858

您可以在站点根目录 .htaccess 中使用此代码:# ensure permalink when url rewriting was enabled # (login.php?r=content/perma&id=6 => /content/perma/?id=6RewriteEngine OnRewriteCond %{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 apacheRewriteCond %{HTTP:Authorization} .RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . login.php [L]
打开App,查看更多内容
随时随地看视频慕课网APP