Forum Moderators: phranque
1. Is there any tangible performance gain by putting rules inside httpd.conf file? Problem is that everytime my host installs a new Apache server (recompiles it, to upgrade for example), the Rewrite rules go away and I have to redo them for all my virtual hosts every time. Having .htaccess in the domain accounts is nicer from this perspective, but my reading on these forums suggests that it's a little inefficient? (I'm on Apache2.2.6).
2. More importantly, I have noticed that two similar rules don't work the same across httpd.conf and .htaccess. Let's say my site root is as follows:
/public_html/site/myscript This php file "myscript" is seen from the web as follows:
http://mypublicsite.com/site/myscript?p=123 Where "p" is the page number. In order to do away with the "?" mark for SEO, I want it to look like this:
http://mypublicsite.com/site/myscript/page123 Now, I can do this two ways:
1. In the folder "site" I can put a .htaccess:
RewriteEngine On
RewriteRule ^myscript/page([0-9]+)$ myscript?p=$1 [L]
This works.
2. In the httpd.conf, I can put this in my site's VirtualHost:
RewriteEngine On
RewriteRule ^/site/myscript/page([0-9]+)$ /site/myscript?p=$1 [L]
But this doesn't work! Any ideas why this may not be working and what I can do? Thanks!
This php file "myscript" is seen from the web as follows:[mypublicsite.com...]
Actually, that looks like part of the problem right there. Why is "site" visible in the URL, and why aren't you using [site.com...] ?
It may be that you've got a disagreement between the DocumentRoot path and the path in your httpd.conf RewriteRules. If so, your server error log should show the path that the server is trying (and failing) to access to serve a page, and any disagreement between that path and the one you expect will be a strong hint as to where things are going wrong.
Jim
Anyway, can't RewriteRule do this -- do rules always have to be from
the root folder on a domain?
Problem is that everytime my host installs a new Apache server (recompiles it, to upgrade for example), the Rewrite rules go away and I have to redo them for all my virtual hosts every time.
My apologies for the "right turn off-topic"!
This is a rather valuable learned lesson.
Don't rely on your host for back up copies of your files (wthether system or otherwise).
My own back ups to my local machine are frequent.
Jd, or anyone else, I have two questions from above:
1. Is putting rules in httpd.conf any better than putting them in individual .htaccess files? In terms of performance efficiencies?
2. In httpd.conf, how can I RewriteRule folders in my website, and not only write rules from the root path?
Thanks!
1. Is putting rules in httpd.conf any better than putting them in individual .htaccess files? In terms of performance efficiencies?
Yes.
This has been answered time and again, by Jim.
[webmasterworld.com...]
I tried putting that in my post above, but I'm at work and WebmasterWorld site is a little slow from here. Hope this message shows up.
That leaves my question no.2, about RewriteRules that are not from the root path. Thanks for any thoughts!
Firstly, yes the httpd.conf rules are much better in performance because they get compiled at starting time. But to see real benefit, turn "AllowOverride None". In a typical WHM/Cpanel context this needs to be in <Directory> tags inside the VirtualHost definition.
Secondly, the rules I have been writing since my postno.1 above actually already work! I just had an aggressive rule for that entire directory BEFORE these ones, with an [L] instruction so that became the last. In other words, Apache was never getting to these rules in the first place. How stupid I feel - but I'm glad it's now working.
Thanks for your help...or lack of it - which pushed me to try harder. I could have searched around this site but sometimes newbies don't know what keywords to use.