【问题标题】:How to write a rule in vhost definition file to redirect example.com > www.example.com如何在 vhost 定义文件中编写规则以重定向 example.com > www.example.com
【发布时间】:2011-03-30 14:09:54
【问题描述】:

我有一个重定向 example.com > www.example.com 的规则。 我删除了 htaccess 文件并将规则放入 /etc/apache2/sites-available/example 虚拟主机定义文件中。并且基本上上述规则停止工作。

这是代码,我将不胜感激,如果知道这件事为什么停止工作会很有趣。

ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/symfony/web

<Directory /var/www/symfony/web>
    AllowOverride None
    Allow from All
    Options FollowSymLinks ExecCGI

    RewriteEngine On

    #RewriteBase /

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]

    # we skip all files with .something
    RewriteCond %{REQUEST_URI} \..+$
    RewriteCond %{REQUEST_URI} !\.html$
    RewriteRule .* - [L]

    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond  %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>

【问题讨论】:

  • 任何人,也许有人可以指出一个寻找的方向?

标签: .htaccess apache2


【解决方案1】:

您可能只想在 apache 中使用 Redirect,而不是使用 .htaccess。见my answer to a similar question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-25
    • 2015-11-18
    • 1970-01-01
    • 2012-10-17
    • 2011-02-18
    • 2017-09-24
    • 2022-11-11
    • 2011-07-06
    相关资源
    最近更新 更多