I would like to use localhost/projects/project1/page/x
instead of localhost/projects/project1/index.php?page=x
. But after I had redirected the URL in .htaccess using RewriteRule, it returned my 404 error page.
Here is my code:
ErrorDocument 404 /projects/project1/pagenotfound.php
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/project1/page/([0-9]*)$ /projects/project1/index.php?page=$1 [L,QSA,NC]
SOLUTION
ErrorDocument 404 /projects/project1/pagenotfound.php
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([0-9]*)$ /projects/project1/index.php?page=$1 [L,QSA,NC]
R=302
flag on theRewriteRule
(it will now externally redirect, rather than internally rewrite, and make it easier to debug) - do you see the redirect? Do you still get the 404?R=302
what URL are you redirected to? ...What URL triggers the 404?/projects/project1/index.php?page=0
?localhost/projects/project1/page/1
in the browsers address bar, after adding theR=302
flag then the redirect/rewrite is not happening. Is mod_rewrite enabled? IsAllowOverride
set appropriately in your server config? Where is your .htaccess file located?