我的htaccess文件中有以下代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.*)$ /index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /index.php [L,QSA]
RewriteRule ^wiki$ /index.php [L,QSA]
这会将 URL 从 http://example.com/w/index.php?title=Page_title
缩短到 example.com/wiki/Page_title
。
我还想将example.com
重定向到 www.example.com
,但我不确定如何在不与其他规则冲突的情况下将其实现到现有的 htaccess 代码中。
如何做到这一点?
在 RewriteBase /
下添加:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]