简体   繁体   English

htaccess重定向在Apache服务器上不起作用

[英]htaccess redirects not working on Apache server

I want to redirect non-www to www version of the website. 我想将非www重定向到网站的www版本。 I've redirected many sites but never had this problem. 我已经重定向了许多站点,但从未遇到过此问题。 I have a typical WP installation on Apache/2.4.27 (Ubuntu) server. 我在Apache / 2.4.27(Ubuntu)服务器上安装了典型的WP。

I've placed the following code before # BEGIN WordPress 我在# BEGIN WordPress之前放置了以下代码

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

I also tried this with no results. 我也尝试了这个,但没有结果。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
</IfModule>

Everything I do, I get: FORBIDDEN - You don't have permission to access / on this server. 我所做的一切,我得到:禁止-您无权访问此服务器上的/。

How to make this redirect to work? 如何使此重定向正常工作? Is there something I should pay attention to on the server side? 在服务器端我应该注意些什么?

Have you tried to modify httpd.conf? 您是否尝试过修改httpd.conf? RedirectPermanent is a good choice to replace .htaccess if not works. 如果无法正常使用RedirectPermanent,则可以替换.htaccess。

example: 例:

<VirtualHost *:80>
ServerName xy.example.com
RedirectPermanent / http://abc.example.com/
# optionally add an AccessLog directive for
# logging the requests and do some statistics
</VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM