Apache 如何使用301永久重定向将www url重定向到非www url?
我的网站正在virtualmin控制面板的虚拟服务器上运行,目前它正在重定向302临时URL,而我已在.htaccess文件中添加了重定向规则 以下是我的.htaccess文件配置:Apache 如何使用301永久重定向将www url重定向到非www url?,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我的网站正在virtualmin控制面板的虚拟服务器上运行,目前它正在重定向302临时URL,而我已在.htaccess文件中添加了重定向规则 以下是我的.htaccess文件配置: Options -Indexes RewriteEngine On RewriteBase / RewriteRule ^index.html$ index.php RewriteRule ^(([a-zA-Z0-9-_]+)?)\.html$ page.php?pagId=$1 RewriteCond %{ht
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ index.php
RewriteRule ^(([a-zA-Z0-9-_]+)?)\.html$ page.php?pagId=$1
RewriteCond %{http_host} !^example.com$ [nc]
RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc,L]
请让我知道我需要在我的web服务器中进行哪些更改,以便它正确重定向301永久重定向
我想以此URL格式重定向我的域的所有请求。您可以使用:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^index\.html$ index.php [L,NC]
RewriteRule ^([\w-]+)\.html$ page.php?pagId=$1 [L,NC,QSA]
我通过编写两条重写规则解决了这个问题。每个vhost中有一个 我在.htaccess文件中保存了相同的内容 > 在/etc/httpd/conf/httpd.conf文件中 > 现在它工作得很好
希望这可能会对其他人有所帮助。感谢anubhava的帮助,但仍然无法正常工作。302重定向。您在浏览器中输入了哪个URL,哪些不起作用?这个.htaccess在哪里?很高兴知道它成功了,你能点击我答案左上角的勾号将答案标记为已接受吗。
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^index\.html$ index.php [L,NC]
RewriteRule ^([\w-]+)\.html$ page.php?pagId=$1 [L,NC,QSA]
<VirtualHost*:80>
.
.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,NE,L]
</VirtualHost>
<VirtualHost*:443>
.
.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,NE,L]
</VirtualHost>