Apache RewriteBase Problem
Posted in Apache, PHP, Regex with tags Apache, PHP, Rewrite Rules, RewriteBase on February 24, 2008 by TaposFive days ago my friend gave me a problem. Problem is bellow
His client gave him a job that fixing the broken link of the site.
That site use rewrite engine to rewrite the .html file to .php file. Also the server uses the virtual hosts.
We saw that the rewrite rules are correctly written and the expected files are present. But the link showed that internal server error and it didn’t find the file.
We have noticed that the server find the files in a directory. So we made a script to find the directory of that script, we have noticed that it is not the same directory. But we didn’t find any problem with the rewrite rules. here is the content of the .htaccess file
# enable mod_rewrite
RewriteEngine on
# correct urls for yahoo bot
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# mod_rewrite rules for ROOT category
RewriteRule ^index([0-9]+).html$ index.php?category=0&page=$1 [QSA,L]
# mod_rewrite rules for categories pages with HTML path option disable
RewriteRule ^(.*)/$ index.php?category=$1 [QSA,L]
RewriteRule ^(.*)/index([0-9]+).html$ index.php?category=$1&page=$2 [QSA,L]
# mod_rewrite rule for suggest listing page
RewriteRule report-listing.php$ report-listing.php [QSA,L]
RewriteRule ^([a-z]+)-listings.html$ listings.php?view=$1 [QSA,L]
RewriteRule ^([a-z]+)-listings([0-9]+).html$ listings.php?view=$1&page=$2 [QSA,L]
# mod_rewrite rules for view listing page
RewriteRule ^([^/]+)-l([0-9]+).html$ view-listing.php?cat=&title=$1&id=$2 [QSA,L]
RewriteRule ^(.*)/([^/]+)-l([0-9]+).html$ view-listing.php?cat=$1&title=$2&id=$3 [QSA,L]
# mod_rewrite rules for additional pages
RewriteRule ^p(.*).html$ page.php?name=$1 [QSA,L]
# mod_rewrite rules for error pages
RewriteRule ^([0-9]+).htm$ error.php?error=$1 [QSA,L]
# mod_rewrite rules for suggest category page
RewriteRule ^suggest-category-([0-9]+).html$ suggest-category.php?id=$1 [QSA,L]
RewriteRule ^LICENSE.htm$ LICENSE.htm [QSA,L]
# mod_rewrite rules for categories pages
RewriteRule ^(.*)_([0-9]+).html$ index.php?category=$1&page=$2 [QSA,L]
RewriteRule ^(.*).html?(.*)$ index.php?category=$1&$2 [QSA,L]
RewriteRule ^(.*).html$ index.php?category=$1 [QSA,L]
ErrorDocument 500 500.htm
ErrorDocument 404 404.htm
ErrorDocument 403 403.htm
ErrorDocument 401 401.htm
After that we made some .html file and put thats in the server and delete the .htaccess file to check that without rewrite rules it works or not. That works!!! So we became confirm that the problem is in rewrite rule.
But the rewrite rules is correct. So where is the problem??????
After googling we have found something about RewriteBase here.
Few days ago i have studied about the virtual hosts of apache, there i have found that the RewriteBase is can be configured for every virtual host. So that I think maybe we found the solution.
Then I have added just one line after the followings
# enable mod_rewrite RewriteEngine on #this line is addedd RewriteBase /
And the things work like a magic.
Have you got this problem before??? If so then what is your experience???
