Elastic Beanstalk 中的 RewriteRule 不起作用
RewriteRule in Elastic Beanstalk not working
我在 .ebextensions/
文件夹中创建了一个包含以下内容的 server.config
文件,并将其部署到我的 Apache/PHP Elastic Beanstalk 实例,但它似乎没有想美化我的网址...
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteRule ^(.*)index\.php$ / [R=301,NC]
RewriteRule ^terms$ /tac.php [NC,L]
RewriteRule ^info$ /information.php [NC,L]
RewriteRule ^visit$ /visit.php [NC,L]
这看起来很简单,但是例如 mysite.com/terms
结果是 404(而 mysite.com/tac.php
工作正常)。
我是否做了一些我只是没有看到(似乎很可能)的愚蠢行为,或者我是否需要在我的 EB 实例的配置中启用某些东西?
这是一个愚蠢的问题。这些规则(如所写)需要在 .htaccess
而不是 *.conf
文件中。
您可以在此处详细了解差异:http://tltech.com/info/rewriterule-in-htaccess-vs-httpd-conf/
Apache matches different things depending on whether the RewriteRule or RewriteCond directive is placed inside a <Directory>
block. And significantly, everything in an .htaccess file is assumed to be in Directory context.
So rules in a .htaccess file behave the same way as rules in a block, which is different from the way rules behave outside a block. Armed with this knowledge, we can fix our httpd.conf file just by moving the rules into the <Directory>
block
我在 .ebextensions/
文件夹中创建了一个包含以下内容的 server.config
文件,并将其部署到我的 Apache/PHP Elastic Beanstalk 实例,但它似乎没有想美化我的网址...
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteRule ^(.*)index\.php$ / [R=301,NC]
RewriteRule ^terms$ /tac.php [NC,L]
RewriteRule ^info$ /information.php [NC,L]
RewriteRule ^visit$ /visit.php [NC,L]
这看起来很简单,但是例如 mysite.com/terms
结果是 404(而 mysite.com/tac.php
工作正常)。
我是否做了一些我只是没有看到(似乎很可能)的愚蠢行为,或者我是否需要在我的 EB 实例的配置中启用某些东西?
这是一个愚蠢的问题。这些规则(如所写)需要在 .htaccess
而不是 *.conf
文件中。
您可以在此处详细了解差异:http://tltech.com/info/rewriterule-in-htaccess-vs-httpd-conf/
Apache matches different things depending on whether the RewriteRule or RewriteCond directive is placed inside a
<Directory>
block. And significantly, everything in an .htaccess file is assumed to be in Directory context.So rules in a .htaccess file behave the same way as rules in a block, which is different from the way rules behave outside a block. Armed with this knowledge, we can fix our httpd.conf file just by moving the rules into the
<Directory>
block