.htaccess mod_rewrite仅适用于www

.htaccess mod_rewrite仅适用于www,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我在一个网站的子目录中有一个.htaccess文件。当URL以www开头时,它可以正常工作,但如果缺少www,它就不能工作 RewriteEngine On RewriteBase /media RewriteRule ^([a-zA-Z0-9_\s\-]+)/?$ index.php?a=$1 [L] RewriteRule ^([a-zA-Z0-9_\s\-]+)/([a-zA-Z0-9_\s\-]+)$ index.php?a=$1&b=$2 [L] 如果我要求,它可以工作,但不

我在一个网站的子目录中有一个.htaccess文件。当URL以www开头时,它可以正常工作,但如果缺少www,它就不能工作

RewriteEngine On
RewriteBase /media
RewriteRule ^([a-zA-Z0-9_\s\-]+)/?$ index.php?a=$1 [L]
RewriteRule ^([a-zA-Z0-9_\s\-]+)/([a-zA-Z0-9_\s\-]+)$ index.php?a=$1&b=$2 [L]
如果我要求,它可以工作,但不能。我错过了什么

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.website.com [NC]
RewriteRule ^(.*) http://website.com%{REQUEST_URI} [R=permanent,QSA,L]

试试看

这与您的重写规则无关,这可能与DNS的配置方式有关

尝试ping两个域:带和不带“www”

下面是我要做的:我配置我的DNS,以便所有带有或不带www的都重定向到同一台电脑:

然后我通过vhost配置处理所有事情:

<VirtualHost *>

    ServerAdmin webmaster@livrepizzas.fr
    DocumentRoot "/web/htdocs/olivier/livrepizzas/dev/website"

    ServerName livrepizzas.fr
    ServerAlias *.livrepizzas.fr
    ...
    ...
    ...
</VirtualHost>

服务器管理员webmaster@livrepizzas.fr
DocumentRoot“/web/htdocs/olivier/livrepizzas/dev/website”
ServerName livrepizzas.fr
ServerAlias*.livrepizzas.fr
...
...
...

这里肯定发生了其他事情。您确定www.mysite.com和mysite.com都映射到Apache配置中的相同目录吗?