从www重定向到非www并允许进一步处理

时间:2014-03-26 09:36:27

标签: .htaccess

我想将网站从www重定向到非www。

主要问题是CMS的.htaccess文件非常复杂。

否则.htaccess开头的这条指令应该有效

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301,L]

我应该在这里设置哪些标志而不是允许.htaccess进一步处理URL?

通用CMS .htaccess

AddDefaultCharset UTF-8
ErrorDocument 404 /404
ErrorDocument 401 /password.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301]


# Админка теперь по адресу /simpla
RewriteRule ^admin/?$  simpla [L]


# Каталог товаров
RewriteRule ^catalog/([^/]+)/?$ index.php?module=ProductsView&category=$1 [L,QSA]
RewriteRule ^catalog/([^/]+)/([^/]+)/?$ index.php?module=ProductsView&category=$1&brand=$2 [L,QSA]

RewriteRule ^products/([^/]+)/?$    index.php?module=ProductView&product_url=$1 [L,QSA]
RewriteRule ^products/?$    index.php?module=ProductsView [L,QSA]

RewriteRule ^brands/([^/]+)/?$  index.php?module=ProductsView&brand=$1 [L,QSA]
RewriteRule ^brands/([^/]+)/page_([^/]+)/?$ index.php?module=ProductsView&brand=$1&page=$2 [L,QSA]

# Поиск товаров
RewriteRule ^search/([^/]+)/?$  index.php?module=ProductsView&keyword=$1 [L,QSA]
RewriteRule ^search/?$  index.php?module=ProductsView [L,QSA]

# Блог
RewriteRule ^blog/([^/]+)/?$    index.php?module=BlogView&url=$1 [L,QSA]
RewriteRule ^blog/?$    index.php?module=BlogView [L,QSA]

# Корзина и заказы
RewriteRule ^cart/?$    index.php?module=CartView   [L,QSA]
RewriteRule ^cart/([^/]+)/?$    index.php?module=CartView&add_variant=$1  [L,QSA]
RewriteRule ^cart/remove/([^/]+)/?$ index.php?module=CartView&delete_variant=$1  [L,QSA]
RewriteRule ^order/([^/]+)/?$   index.php?module=OrderView&url=$1  [L,QSA]
RewriteRule ^order/?$   index.php?module=OrderView  [L,QSA]

# Для пользователей
RewriteRule ^user/login/?$  index.php?module=LoginView  [L,QSA]
RewriteRule ^user/register/?$   index.php?module=RegisterView  [L,QSA]
RewriteRule ^user/logout/?$ index.php?module=LoginView&action=logout  [L,QSA]
RewriteRule ^user/password_remind/?$    index.php?module=LoginView&action=password_remind  [L,QSA]
RewriteRule ^user/password_remind/([0-9a-z]+)/?$    index.php?module=LoginView&action=password_remind&code=$1  [L,QSA]
RewriteRule ^user/?$    index.php?module=UserView  [L,QSA]

# Google sitemap
RewriteRule ^sitemap.xml?$  sitemap.php  [L,QSA]

# XML
RewriteRule ^yandex.xml?$   yandex.php  [L,QSA]

# feedback
RewriteRule ^contact/?$ index.php?module=FeedbackView  [L,QSA]

#downloads
RewriteRule ^order/([^/]+)/([^/]+)/?$   index.php?module=OrderView&url=$1&file=$2  [L,QSA]


# Статические страницы
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^/?$    index.php?module=MainView&page_url= [L,QSA]

# Ресайз картинок на лету
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^files/products/(.+) resize/resize.php?file=$1&token=%{QUERY_STRING}
#RewriteCond %{THE_REQUEST} ^GET\ (.*)files/products/(.*)\?([A-z0-9]*) 
#RewriteRule ^files/products/(.+) resize/resize.php?file=%2&token=%3 [L,NE]

1 个答案:

答案 0 :(得分:0)

从最后一行删除L将允许它继续。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301]

[L]是一个标志,如果此规则匹配,则不会执行其他规则匹配。