【问题标题】:mod_rewrite not working for httpsmod_rewrite 不适用于 https
【发布时间】:2014-02-13 18:07:42
【问题描述】:

我在一个 ec2 redhat 实例上运行 Apache。我使用 conf.d/ssl.conf 启用并运行了 https。我正在尝试重写 url,以便用户不必添加 .php 扩展名。但是,由于某种原因,它不起作用。这是我添加到 ssl.conf 中的内容:

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/https-html"

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

.
.
.

</VirtualHost>

我得到一个没有 .php 扩展名的 404,并且它与扩展名一起工作正常。

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    好吧,如果您想使用一个没有 php 扩展名的 URL,但又希望它重定向到一个,请尝试以这种方式重写规则。 这样你就可以使用像http://www.yoursite.com/somefile这样的URL,它会重定向到http://www.yoursite.com/somefile.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*) $1.php [L]
    

    【讨论】:

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