![]() |
htaccess problem
I used to use a portal on my site but i recently removed it so i have been using the following htaccess file to direct all users to my forum. The problem with this is that i can no longer get to my phpmyadmin page which is http://www.mysite.com/phpmyadmin/ as it always changes the url to http://www.mysite.com/forum/phpmyadmin/
RewriteEngine On RewriteBase / RewriteRule (.*) http://www.mysite.com/forum/$1 [R,L] What have i done wrong? |
The rewrite rule matches the . character as a wildcard for anything, the * matches 0 or more occurances of the character before it. That's why you're getting that result. It doesn't check for the directory existance at all, it just matches anything and sticks it where you tell it to go.
Honestly, I recommend just removing the /forum subdirectory all together. No muss no fuss, can you dig it? But if you absolutely want to have a subdirectory, then you can easily create an index.php file that redirects instead of using the htaccess. PHP Code:
I wouldn't advise using htaccess rewrite rules since you'd have to go crazy with manual definitions for any subdirectory you want to add in the future. |
Thanks i'll give that a try, i would move my forum back to the main directory but just thinking about all the urls on my site that contain /forum/ just makes me shiver so i think i'll have to keep it.
|
RewriteEngine On
RewriteBase / RewriteRule (.*) http://www.mysite.com/forum/$1 [R,L] RewriteCond %{REQUEST_URI} !^/phpmyadmin RewriteRule ^(.*)$ phpmyadmin/$1 [L] RewriteCond %{REQUEST_URI} !^/newsubdir RewriteRule ^(.*)$ newsubdir/$1 [L] If you want to add more subdir's just adjust the last two lines and rename the phpmyadmin/newsubdir to your new dir name. As well, htaccess if far more efficient than having php do the redirects for you. |
Yes, for the initial redirect you're correct that it's more efficient for the server to do it that way. However, the .htaccess file is checked and parsed for every single page request. The PHP redirect script is only parsed for the initial, not every single request. So ultimately, the .htaccess is not more efficient - and the longer the .htaccess file gets (the more subdirectories added to the exeption list) the less efficient it is.
|
That would be based on your opinion or on actual page load testing that you have done?
|
Consider:
Every single time you load a page from the apache server, you're adding the .htaccess to the program calls. The server has to parse that .htaccess every single time, so the longer it gets the longer it takes to parse. Then it has to go through and compare everything in the request to the values in the .htaccess file. After that, it has to decide what to do based on what it finds. This happens every time you load a page. If apache doesn't find a .htaccess file in the current directory, it goes up a directory and looks in there until it reaches the webroot directory. It is still more efficient than calling the PHP engine and having it parse the PHP file and then redirectiong, though. That is why the initial http://www.mysite.com/ call is more efficient with .htaccess. However, then the site becomes http://www.mysite.com/forums and it's still parsing and comparing that .htaccess file and its values since there's no .htaccess in the forum directory. Ultimately, that makes the rest of the website run less efficiently. Using the PHP redirect, you take a slightly heavier hit on the initial request to http://www.mysite.com/, but from there on out when http://www.mysite.com/forums is accessed there's no overhead from the .htaccess file. One could solve the issue by making a blank .htaccess file in the forums directory, but that's just bad programming practice in my honest opinion. |
Sorry, but your opinion is based on what facts/load testing?
|
Code:
RewriteEngine on just add this Code:
RewriteCond %{HTTP_HOST} ^(www\.)?ur site goes here.com/cpanel/$ [NC] |
Quote:
You were probably referring to the idea that .htaccess can make a website run less efficiently. That's not an opinion, because I don't believe that magic pixies live in computers to execute instructions without cost. Like it or not, apache checks the .htaccess for every request. If the file exists, it has to do string matching - then it has to do string replacement if it finds a match - then it processes things "normally". If you think this can happen in a server without any cost, no toll on the memory or processor, then you must believe that fairies exist and live in mushrooms. lol In terms of differences between load, it's negligible. You will not see a difference. But you said it was more efficient to use .htaccess, and that's simply not true. I've done all I can for you, I don't know how to put it any more simply. If you execute more instructions on the server's processor for every page request, it is less efficient. |
All times are GMT. The time now is 02:21 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|