.htaccess URL Rewrite Failing - The requested URL was not found on this server
Remove the 'RewriteBase /site' and try removing the / before index.php The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]
user1100149
Updated on June 04, 2022Comments
-
user1100149 almost 2 years
I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is
http://localhost/site
andwww.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
-
C.A. Vuyk about 11 yearsDoes the directory localhost/site/home ALSO exists in reality? This will prevent redirecting to index.php?page=home.
-
user1100149 about 11 years
home
isn't a directory. It identifies the page, so should be rewritten toindex.php?page=home