: Returning 404 error after using RewriteRule on localhost 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
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= [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= [L,QSA,NC]
More posts by @Sherry384
1 Comments
Sorted by latest first Latest Oldest Best
My .htaccess is in the same directory as the index.php, so: localhost/projects/project1/.htaccess
That's the problem, or rather your RewriteRule pattern is the problem, depending on how you look at it.
In .htaccess (per-directory) files, the per-directory prefix is first removed from the URL before matching against the pattern. So, if your .htaccess file is at /projects/project1/.htaccess, then your RewriteRule pattern needs to exclude /projects/project1/ from the start (for the same reason you remove the / prefix from the pattern when in the document root). In other words...
RewriteRule ^page/([0-9]*)$ /projects/project1/index.php?page= [L,QSA,NC]
Or, move your .htaccess file to the document root.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.