Jump to content
Larry Ullman's Book Forums

Is There Better Way For My Mod Rewrites?


Recommended Posts

I've been thinking about my ModRewrites.

I am adding new files every day.

There will be about 150 total.

But I might be adding a new product line that could increase it to about 400.

I'm not sure until I get details and I don't know if that matters.

 

What I'm thinking about is that all these modrewrites are going to slow things down. What I'm doing now works great and it gives user ability to type abbreviations. But if it will slow things down, should I even do it that way?

 

What I really only need, is when my program calls up a name, the modrewrite finds the correct file. My program uses the canonical name which is what I want.

Would it make sense for me to do this, if this can even be done:

 

All my file names start with a condition name followed by hyphen followed by treatment.php: condition-name-treatment.php, and my code calls the file without the .php. Could I say [a-z\-] followed by "-treatment" gets .php added.

 

If this can be done would it be faster?

So would it be worthwhile doing?

 

I should mention there are a few other files that don't use the condition-treatment format so this modrewite shouldn't catch those.

 

Here is example of what I do now:

RewriteRule ^head|migra[a-z_\-\./]*$ migraines-treatment.php

Link to comment
Share on other sites

I'm not sure that I understand. Will this be faster than what?

 

In terms of "worthwhile", there are two issues: maintenance and performance. In terms of maintenance, will the system stop growing at 400 or could it continue growing ad infinitum? In terms of performance, will there be other high demands on the system?

 

One thing you could do would be to use one directory for all these, that way you don't have to worry about catching things that shouldn't be caught. In fact, in that situation, you could just rewrite /a/something to /a/something.php

 

You could also consider moving this to a database system. To me, multiple, similar HTML files screams like a good opportunity to convert to a dynamic database-driven site.

Link to comment
Share on other sites

I was just concerned about the time to bring up a webpage because of so many mod_rewrites. I wanted to give you an idea of the numbers of files involved, which seems like a lot to me, but it might not be a lot for the filesystem. I expect to be getting a new product line but I don't know if it will only overlap what I now have or if it will include additional to raise it from about 150 to about 400. And I don't think there will be other product lines added.

 

The work of writing the .htaccess file is not significant, now that I'm pretty comfortable with it. I do a batch at a time. I've included at the end, what my mod_rewrites are currently, because I didn't provide enough information before.

 

Putting these files into a subdirecty is a possibility. If that makes things easier, I think it's a good idea. But the only thing is, from what I've read, a big advantage of mod_rewrites is that my page name never has to change, even if I change my file name or location. Which is desirable for SEO and also if people have an old link it will still work. But now you're saying I should change my page name from condition-name-treatment to subdir/condition-name-treatment. But I think my confusion is because I only have limited understanding of mod_rewrites.

 

When you write /a/something, I think you mean /a is a subdirectory of my site like this: sitename.com/a/something.php, and not outside my webfiles. Correct?

 

Can you show me syntax of how it would work if I did subdir/condition-name-treatment and mod_rewrite adds .php to it for different condition names?

 

But another thing I'm asking, is this something I even need to care about. Maybe this number of mod_rewrites won't slow things down.

 

I'm not aware of any other high demands on the system. User has to login to place order but all the secure pages are separate from these product pages. My code moves back and forth between the secure pages and the product pages which don't use sessions or cookies. The only thing I've been thinking, right now they only can purchase one at a time. If I want to let them have a 'shopping cart' of some sort then I might want to have cookie remember that on the product side to pass it to the secure side. This is thinking into the future. I want to try to avoid this if I can, with my usual goal of keeping thinks as simple as possible. What other high demands might affect the mod_rewrites?

 

As for making my site database driven, I certainly have considered that. The main reason I'm not is SEO. For one thing there are natural differences in features and secondly I also don't want my pages to look like clones with different names. Already they are highly similar. But I'm always looking for ways to differentiate. Both for SEO and also for users, who will see similar but not just a name change, page to page. So I have to type in the individual parts either into HTML or into database. The real work is in thinking up keywords and trying to find what's special about a condition or treatment.

 

 

 

RewriteEngine On

RewriteRule ^addict[a-z\-\./]*$ addiction-treatment.php

RewriteRule ^allerg[a-z\-\./]*$ allergies-treatment.php

RewriteRule ^alz[a-z\-\./]*$ alzheimer-treatment.php

RewriteRule ^anger|rage[a-z\-\./]*$ anger-treatment.php

RewriteRule ^anxi|panic[a-z\-\./]*$ anxiety-treatment.php

RewriteRule ^gout|arth[a-z\-\./]*$ arthritis-gout-treatment.php

RewriteRule ^emph|asthm[a-z\-\./]*$ asthma-emphysema-treatment.php

RewriteRule ^back[a-z\-\./]*$ back-pain-treatment.php

RewriteRule ^vir|bacter[a-z\-\./]*$ bacterial-viral-infections-treatment.php

RewriteRule ^bells[a-z\-\./]*$ bells-palsy-treatment.php

RewriteRule ^sunb|burn[a-z\-\./]*$ burns-treatment.php

RewriteRule ^c-sympt|sympt[a-z\-\./]*$ c-symptoms-treatment.php

RewriteRule ^cancer[a-z\-\./]*$ cancer-treatment.php

RewriteRule ^pals|cereb[a-z\-\./]*$ cerebral-palsy-treatment.php

RewriteRule ^sad|depres[a-z\-\./]*$ depression-treatment.php

RewriteRule ^diab[a-z\-\./]*$ diabetes-treatment.php

RewriteRule ^const|diar[a-z\-\./]*$ diarrhea-constipation-treatment.php

RewriteRule ^ear[a-z\-\./]*$ earache-treatment.php

RewriteRule ^faq[a-z\-\./]*$ faq.php

RewriteRule ^phob|fear[a-z\-\./]*$ fear-phobia-treatment.php

RewriteRule ^food[a-z\-\./]*$ food-poisoning-treatment.php

RewriteRule ^genital[a-z\-\./]*$ genital-herpes-treatment.php

RewriteRule ^guide[a-z\-\./]*$ guide-treat-illnesses.php

RewriteRule ^health-conta|conta[a-z\-\./]*$ health-contact.php

RewriteRule ^health-contr|contr[a-z\-\./]*$ health-contribute.php

RewriteRule ^heart[a-z\-\./]*$ heart-disease-treatment.php

RewriteRule ^heat[a-z\-\./]*$ heat-exhaustion-treatment.php

RewriteRule ^hemo[a-z\-\./]*$ hemophilia-treatment.php

RewriteRule ^(hiv|aids)($|[\-\./][a-z\-\./]*$) hiv-aids-treatment.php

RewriteRule ^hives|urtic[a-z\-\./]*$ hives-treatment.php

RewriteRule ^high|hyperten[a-z\-/]*$ hypertension-treatment.php

RewriteRule ^ins[a-z\-\./]*$ insurance-alternative.php

RewriteRule ^kidn[a-z\-/]*$ kidney-failure-infection-treatment.php

RewriteRule ^leuk[a-z\-\./]*$ leukemia-treatment.php

RewriteRule ^macu[a-z\-\./]*$ macular-degeneration-treatment.php

RewriteRule ^mental[a-z\-\./]*$ mental-sharpening-treatment.php

RewriteRule ^head|migra[a-z\-\./]*$ migraines-treatment.php

RewriteRule ^naus[a-z\-\./]*$ nausea-treatment.php

RewriteRule ^herpes|oral[a-z\-\./]*$ oral-herpes-treatment.php

RewriteRule ^parkin[a-z\-\./]*$ parkinsons-treatment.php

RewriteRule ^drum|perf[a-z\-\./]*$ perforated-eardrum-treatment.php

RewriteRule ^preg[a-z\-\./]*$ pregnancy-problems-treatment.php

RewriteRule ^prost[a-z\-\./]*$ prostatitis-treatment.php

RewriteRule ^ptsd[a-z\-\./]*$ ptsd-treatment.php

RewriteRule ^retard[a-z\-\./]*$ retardation-mental-treatment.php

RewriteRule ^shing[a-z\-\./]*$ shingles-treatment.php

RewriteRule ^sickle[a-z\-\./]*$ sickle-cell-anemia-treatment.php

RewriteRule ^sids[a-z\-\./]*$ sids-treatment.php

RewriteRule ^skin[a-z\-\./]*$ skin-infections-treatment.php

RewriteRule ^sleep[a-z\-\./]*$ sleep-disorders-treatment.php

RewriteRule ^stroke[a-z\-\./]*$ stroke-treatment.php

RewriteRule ^gum|tooth[a-z\-\./]*$ tooth-gum-pain-treatment.php

RewriteRule ^tremor[a-z\-\./]*$ tremors-treatment.php

RewriteRule ^tumor[a-z\-\./]*$ tumors-treatment.php

RewriteRule ^pertus|whoop[a-z\-\./]*$ whooping-cough-treatment.php

RewriteRule ^wound[a-z\-\./]*$ wound-healing-treatment.php

Link to comment
Share on other sites

Random answers:

 

- This is not a lot of files for the file system.

 

- Yes, you'd create an /a subdirectory. That subdirectory would have:

RewriteRule ^([a-z\-\./]*)/?$ $1.php

That would redirect /a/hives-treatment to /a/hives-treatment.php and /a/ptsd-treatment to /a/ptsd-treatment.php

 

- The inefficiency of your rules as you have them, and as they are in the main directory, is that the Web server will check EVERY rule (all 400) for EVERY request made of ANY resource in the main Web directory OR ANY SUBDIRECTORIES. Each image, each CSS script, each JS script, even in subdirectories, will force a check against all 400 rules. Not good.

 

- Changing to a database-driven system would not impact your SEO, if done right.

 

- SEO is not the holy grail. It's marginally useful, don't give it too much credit. Having good content trumps all.

 

- Finally, for your rules, you have, for example, this:

RewriteRule ^addict[a-z\-\./]*$ addiction-treatment.php

I would use a rule like that if there are multiple possible values that would get redirected to addiction-treatment.php If that's not the case and there's a one-to-one association, then RedirectMatch would be more appropriate. mod_rewrite is for matching patterns.

Link to comment
Share on other sites

Thank you for this good advice about putting these files into subdirectory.

I will do that for efficiency. And it will organize my files also.

 

I will always be calling the files from my program with the same name but when I started with the mod_rewrites, I noticed how convenient to let user type shorter url, etc. But I don't really need that. So for efficiency I will do what you are suggesting. It makes good sense to me.

 

I experimented a little and changed your syntax to this:

RewriteRule ^([a-z\-]*)/?$ $1.php

 

With your syntax it gave: Internal Server Error.

These RegEx are still partly mystery to me. But my rule above appears to work.

One confusing thing is it works if I call url 'name' or 'name.php'.

 

I experimented some more and I have this:

RedirectMatch 301 ^([a-z\-\./]*)/?$ $1.php

And an interesting thing is it works whether or not I put the \./ in or leave it out.

 

If you think the RedirectMatch is the best way for me to do it then that's what I'm going to do.

 

For your information, and anyone else with interest, I just found a website that explained about the 301 redirect, which we want to be using (probably). I didn't have that on my RewriteRules and if I don't put it in the RedirectMatch it will default to 302. 302s are very, very bad for SEO (from what I've read). (I know SEO isn't the holy grail but I'm doing what I can.) To add the 301 to RewriteRule add this to the end [R=301,L]. Like this:

RewriteRule ^([a-z\-]*)/?$ $1.php [R=301,L]

 

Do I still need to turn the RewriteEngine On? This is what I have now:

<code>

<IfModule mod_rewrite.c>

RewriteEngine On

RedirectMatch 301 ^([a-z\-\./]*)/?$ $1.php

</IfModule>

</code>

 

Link to comment
Share on other sites

Actually, I don't understand why it seemed to work before.

Now the only rule that works is this one:

RewriteRule ^([a-z\-]*)/?$ $1.php

If I add the 301 part to it it does not work.

And the RedirectMatch does not work.

Maybe there is something you see in my syntax.

Link to comment
Share on other sites

You don't want to do a 301 redirect. A 301 redirect indicates that the linked content has moved permanently. That's not what's happening in your situation. The user is using a URL that you want them to use and you don't want them to be aware of the redirection.

Link to comment
Share on other sites

Here's what I'm thinking. If I did RedirectMatch then it will issue 302 and I don't want that.

If I do RewriteRule perhaps it doesn't issue 302 because I am just doing a rename, so I don't have to issue 301.

If this is the case then I will do the RewriteRule. It works great and it will simplify everything for me.

Link to comment
Share on other sites

 Share

×
×
  • Create New...