在现有的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文件位置断点
那么我应该把它放在哪里呢?

这是最终的.htaccess文件的工作-

# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) http://www.example.com/$1 [L,QSA]
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

[R=301]部分改为[L,QSA]部分解决了301错误部分

相关内容

  • 没有找到相关文章

最新更新