I am using a subdomain URL for my test server. Something like:
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?
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
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.