Forum Moderators: phranque
I've just changed my site from old ugly subdomain.domain.com/index.htm to subdomain.domain.com/index/ which is forwarded to template.php. Base is set to ht*p://subdomain.domain.com/ so all links are relative. Everything works as intended except that somewhere along this process the load times have increased and I'm not sure where the culprit lies so I thought I'd start by asking here if the mod_rewrites I've done look kosher.
The following should be taken care of the in .htaccess.
RewriteEngine On
RewriteBase /
RewriteRule ^$ http://subdomain.domain.com/index/ [R=301,L]
# fix missing trailing slash
# -> the file has not an extension
RewriteRule!\..{3,4}$ - [C]
# -> and does not end up with a slash
RewriteCond %{REQUEST_URI}!^.*/$
# => redirect
RewriteRule ^(.+)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_URI}!^(switcher\.php)$
RewriteRule ^([a-z0-9_/-]+)$ /template.php?page=$1 [NC,QSA,L] Hopefully I haven't missed anything essential. Any and all input on the matter will be greatly appreciated. If all this checks out I guess I'll be heading over to the php forum. :)
Cheers, Pontus
Wemlcome to WebmasterWorld!
I don't see anything terribly wrong, except for a possible deadloop in the last rule. Some other minor tweaks may result in minor performance improvements:
RewriteEngine On
RewriteBase /
RewriteRule ^$ http://subdomain.example.com/index/ [R=301,L]
# fix missing trailing slash
# -> If the file has no extension
[b]RewriteCond %{REQUEST_URI} !\..{3,4}$[/b]
# -> and does not end up with a slash
RewriteCond %{REQUEST_URI} [b]!/$[/b]
# => redirect to add trailing slash
RewriteRule ^(.+)$ [b]http:[i][/i]//subdomain.example.com[/b]/$1/ [R=301,L]
# Internally rewrite all except template and switcher to template.php
RewriteCond %{REQUEST_URI} [b]!^(template¦[/b]switcher)\.php$ [b][NC][/b]
RewriteRule ^([a-z0-9_/-]+)$ /template.php?page=$1 [NC,QSA,L]
By explicitly preventing requests for template.php from being rewritten, this deadloop can be avoided.
Change all broken pipe "¦" characters to solid pipe characters (usually Shift-\) before use.
Jim
I'll be dissecting the changes later on to hopefully learn something new. That's my preferred way of learning; trying - succeeding - perfecting.
Unfortunately my host doesn't supply errorlogs and after reading up on the subject I can see why. Guess I'll have to go back to trying to configure my local server. Feels like I'm opening up Pandora's Box here.
I have come up with a few other questions where a yes/no will be more than enough. Not afraid of digging in but sometimes it's nice to get a general idea.
1. My unix-path in this case is /customers/dindomän.se/dindomän.se/httpd.www/ftg/, does that mean that every request will have to go through every directory?
2. My template.php is using 4 require_once's (2 php and 2 htm-files) are they also going through the .htaccess?
3. If yes on the above question, I'm guessing it should be enough to exclude them from the last rewriterule? (If it is indeed a performance issue I'll look into a different structure.)
4. Is it possible to implement the same unix-path structure virtually on my local server? Would make it easier to see the performance bit I guess.
I'm sure I had more questions before I sat down to type it. :lol: Thanks again.
Pontus
No, only the path from Document_Root -the path accessible via HTTP- is traversed.
2. My template.php is using 4 require_once's (2 php and 2 htm-files) are they also going through the .htaccess?
No php requires access resources through the filesystem, not by using HTTP connections.
3. If yes on the above question, I'm guessing it should be enough to exclude them from the last rewriterule? (If it is indeed a performance issue I'll look into a different structure.)
--See above--
4. Is it possible to implement the same unix-path structure virtually on my local server? Would make it easier to see the performance bit I guess.
Yes, if I understand the question.
Jim