在现有 bbpress htaccess 文件中的何处添加 www 重定向代码?
我最近在我的域上安装了 bbpress。它带有一个 .htaccess 文件,如下所示 ->
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
现在我想在里面添加一段非www到www的重定向代码,即->
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
我应该把它放在哪里?我发现这里我应该把它放在就在 RewriteEngine On
之后,但这样做会导致 UI 中断。 CSS 文件位置中断。
那么我应该把它放在哪里呢?
I recently installed bbpress on a domain of mine. and it came with a .htaccess file which looks like this ->
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
Now I want to add a non-www to www redirect code in it, which is ->
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
Where should I put it? I found here that I should put it right after RewriteEngine On
but doing so makes the UI break. CSS file locations break.
So where should I put it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是最终运行的
.htaccess
文件 -将
[R=301]
部分更改为[L,QSA]
解决了 301 错误部分..Here is the final
.htaccess
file that's working -Changing the
[R=301]
part to[L,QSA]
solved the 301 error part..