svenyonson
svenyonson

Reputation: 1919

mod_rewrite not working for https

I am running Apache on an ec2 redhat instance. I have https enabled and working, using conf.d/ssl.conf. I am trying to rewrite urls such that the user doesn't have to add the .php extension. But, for some reason, it is not working. Here is what I have added to 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>

I get a 404 without the .php extension, and it works fine with the extension.

Upvotes: 0

Views: 466

Answers (1)

Panama Jack
Panama Jack

Reputation: 24468

Well if you want to use a URL that does NOT have a php extension on it but you want it to redirect to one, the try your rewrite rules this way. This way you can use a URL like this http://www.yoursite.com/somefile and it will redirect to http://www.yoursite.com/somefile.php

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

Upvotes: 0

Related Questions