Question

I am using a subdomain URL for my test server. Something like:

http://dev.mysite.com

I have the following in my .htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1
RewriteRule ^about/(.*)$ /about.php?request=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

The above works well on the production (non-subdomain) set of URLs. But it doesn't quite make the cut on my dev box. For example, if I type in

http://dev.mysite.com/about

I get a 404 error. But the following with the appended .php extension works.

http://dev.mysite.com/about.php

I am guessing this has something to do with the first rewrite condition that deals with the www subdomain. How would I modify my .htaccess file to account for the dev subdomain?

Was it helpful?

Solution

It appears that your .htaccess is not enabled.

Verify whether your .htaccess is enabled or not, by putting same garbage text on top of your .htaccess and see if it generates 500 (internal server) error or not?

To enable .htaccess your httpd.conf file will need this line:

AllowOverride All

OTHER TIPS

You need at least AllowOverride All or AllowOverride FileInfo in order for the htaccess file to work in your server/vhost config. FileInfo is for things like mod_rewrite.

Additionally, make sure you have mod_rewrite loaded.

You'll also want to change this condition:

RewriteCond %{REQUEST_FILENAME}.php -f

to:

RewriteCond %{DOCUMENT_ROOT}/$1.php -f

because mod_rewrite will recognize that about has a php file and make it so /about/something passes the -f test, resulting in /about/something.php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top