Issue
I've created a server.config
file within an .ebextensions/
folder with the following content, and deployed it to my Apache/PHP Elastic Beanstalk instance, but it doesn't seem to want to prettify my URLs...
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteRule ^(.*)index\.php$ /$1 [R=301,NC]
RewriteRule ^terms$ /tac.php [NC,L]
RewriteRule ^info$ /information.php [NC,L]
RewriteRule ^visit$ /visit.php [NC,L]
It seems simple enough, but for example mysite.com/terms
results in a 404 (whereas mysite.com/tac.php
works fine).
Have I done something silly that I'm just not seeing (seems likely), or do I need to enable something in my EB instance's config?
Solution
It was a silly gotcha. These rules (as written) need to be in .htaccess
not a *.conf
file.
You can learn more about the differences here: 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
Answered By - Chuck Le Butt Answer Checked By - Marie Seifert (WPSolving Admin)