.htaccess 如何使用查询参数将所有www请求重定向到非www
我正在尝试将所有www URL重定向到非www URL 发件人:.htaccess 如何使用查询参数将所有www请求重定向到非www,.htaccess,mod-rewrite,url-rewriting,apache2,.htaccess,Mod Rewrite,Url Rewriting,Apache2,我正在尝试将所有www URL重定向到非www URL 发件人: 1. http://example.com/web-url 2. http://www.example.com/web-url 3. https://www.example.com/web-url 致: 我使用的配置如下 RewriteEngine on # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f
1. http://example.com/web-url
2. http://www.example.com/web-url
3. https://www.example.com/web-url
致:
我使用的配置如下
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
综上所述,一切似乎都没问题,但第三个选项没有按预期工作。问题是
https://www.example.com/web-url
被重定向到https://example.com/index.php
有人能告诉我我的配置有什么问题吗?更改规则的顺序按预期工作
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
在进行内部重写之前,您需要执行外部重定向。@CBroe我该怎么做?通过更改.htaccess文件中这些行的顺序…@CBroe,谢谢,伙计,成功了。更改上述规则的顺序按预期工作。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php