【问题标题】:mod_rewrite not working with subdomainmod_rewrite 不适用于子域
【发布时间】:2012-12-17 12:57:52
【问题描述】:

所以我在这件事上花了太多时间 - 有点绝望。

.htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^submit/?$ submit.php [NC,L]

/etc/apache2/sites-available/applicapple:

<VirtualHost *:80>
    ServerAdmin support@perpetualcontrast.com

    DocumentRoot /var/www/applicapple
    ServerName applicapple.localhost
    <Directory /var/www/applicapple/>
            Options Indexes FollowSymLinks MultiViews
            RewriteEngine On
            AllowOverride All
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

submit.php 肯定存在。 访问 applicapple.localhost/submit 时:

目录中有submit.php,我得到The requested URL /submit was not found on this server.

如果我删除 submit.php,我会得到 The requested URL /submit.php was not found on this server.

如果我访问 localhost/applicapple,它会按预期工作。

有人能告诉我这里发生了什么吗?

【问题讨论】:

  • 如果你尝试使用 sub.localhost/submit/ 而不是 sub.localhost/submit 呢?
  • 效果一样,输出没有区别):

标签: linux apache mod-rewrite


【解决方案1】:

看起来你忽略了'/'

试试这个

RewriteRule ^/submit/?$ submit.php [NC,L]

【讨论】:

  • 对不起-效果没有区别):
  • 您能否添加您的虚拟主机配置以及访问、错误和重写日志的尾部输出?
【解决方案2】:

问题是 Apache 中的 MultiViews 选项在目录中搜索具有相同名称的文件,因此如果 /submit.php 存在,/submit 会被解释为 /submit.php。我关闭了这个选项,它现在可以正常工作了。

【讨论】:

    【解决方案3】:

    你的 RewritRule 是

    重写规则 ^/submit/?$ submit.php [NC,L]

    我认为它不会按原样工作,因为它意味着'匹配 /submit to submit.php 所以如果 url 是 www.xyz.com/submit 它将被重定向为 www.xyz.comsubmit.php 这将导致“400 Bad request”,因为您的 apache 服务器不知道如何处理该请求。

    我在我的电脑上测试了配置,只需编辑重写规则以重定向到 /submit.php 而不是 submit.php 即可解决问题。

     Options +FollowSymLinks
     RewriteEngine On
     RewriteRule ^/submit/?$ /submit.php
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多