2
votes

I'm facing a quite strange behaviour of my .htaccess. Whenever I try to access a link rewritten by mod_rewrite, my .htaccess is refering to the root and not the subdirectory I'm working in. My folder structure looks like that:
htdocs/ blog6/ .htaccess
My .htaccess looks like that:

Options +FollowSymLinks -MultiViews

ErrorDocument 401 /core/error/401.php
ErrorDocument 403 /core/error/403.php
ErrorDocument 404 /core/error/404.php
ErrorDocument 500 /core/error/500.html

RewriteEngine on
RewriteBase /blog6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

But whenever I try to access a file through a rewritten url, I get a 404 error and the log says:

C:/xampp/htdocs/index.php' not found or unable to stat

So it seems like my .htaccess wants to access the file in the htdocs instead of using the subdirectory. When I write /blog6 in my rewriteRule, everything works fine, but why RewriteBase isn't working properly? If it's important, I'm using <base> in my html

1
What URL do you open in browser that causes this 404? I believe this .htaccess is in /blog6/ directory?anubhava
@anubhava yes, the .htaccess is in /blog6/. I open http://localhost/blog6/login which should be the rewritten form of http://localhost/blog6/index.php?page=login. If I put a blog6/ in front of the rewriteRule, it looks like that: RewriteRule ^([^/]*)$ /blog6/index.php?page=$1 [L] and works. And that is the point where it's confusing me, as the rewriteBase has no impact...Kommodore

1 Answers

1
votes

RewriteBase works only if you provide relative URL in target of RewriteRule so change your code to:

Options +FollowSymLinks -MultiViews

ErrorDocument 401 /core/error/401.php
ErrorDocument 403 /core/error/403.php
ErrorDocument 404 /core/error/404.php
ErrorDocument 500 /core/error/500.html

RewriteEngine on
RewriteBase /blog6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]