Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 从www重定向到非www并允许进一步处理_.htaccess - Fatal编程技术网

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

.htaccess 从www重定向到非www并允许进一步处理,.htaccess,.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.htacces

我想将网站从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]

从最后一行中删除
L
将允许其继续

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

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

是否有任何理由进一步处理规则,而不是重定向到“正确”的主机名?这是行不通的,当然,除非您进行大量重复,长话短说:这不值得……我相信[R=301]将生效…我错了吗?
[R=301]
将告诉浏览器(和搜索引擎)页面已永久移动到新地址如果我只删除L,我会得到500个内部服务器错误,如果我删除这些重写条件和重写规则,所有工作正常(当然没有www重定向)尝试删除除前三行以外的所有行,以查看是否仍会导致500内部错误。如果没有,你能编辑你的第一篇文章并复制你的htaccess文件的全部内容吗?我已经添加了通用的CMS.htaccess