Using querystring IDs to create readable URLs

David,

I had initially set this up using a ‘shortname’ to match my sites. Looking at this now, I’m assuming that for me to match successfully to a domain I’ll need to store the domain name in the database, but this will then have an effect on my rewriting as I’m currently matching on the shortname but need to also match the domain name.

Could you help me? Do I need to match to the domain name

Domain: www.branch-1.com
Shortname: branch-1
Points to: www.parentcompany.com/klvc/klvc_store.php?klvc=branch-1

Domain: www.branch-2.com
Shortname: branch-2
Points to: www.parentcompany.com/klvc/klvc_store.php?klvc=branch-2

vhosts (local on port 81)


<VirtualHost *:81>
    ServerName local.branch-1.com
    DocumentRoot C:/wamp/www/parentcompany
</VirtualHost>
<VirtualHost *:81>
    ServerName local.branch-2.com
    DocumentRoot C:/wamp/www/parentcompany
</VirtualHost>

Current .htaccess


Options +FollowSymlinks
RewriteEngine on

#Need rewritecond in here

#Catch specific reference to a klvc page 
RewriteRule ^klvc/([-a-zA-Z0-9]+)/([0-9]+)$ /klvc/klvc_store.php?klvc=$1&mantext_id=$2 [L]
RewriteRule ^klvc/([-a-zA-Z0-9]+)$ /klvc/klvc_store.php?klvc=$1 [L]

#Catch specific reference to a news article
RewriteRule ^klvc/([-a-zA-Z0-9]+)/news/article-([0-9]+)$ /klvc/klvc_news.php?klvc=$1&newsid=$2 [L]
RewriteRule ^klvc/([-a-zA-Z0-9]+)/news$ /klvc/klvc_news.php?klvc=$1 [L]
 
#Catch specific reference to a booking form
RewriteRule ^klvc/([-a-zA-Z0-9]+)/booking/([a-zA-Z0-9]+)$ /locator/book/?id=$2 [L]

#Catch specific reference to a contact form
RewriteRule ^klvc/([-a-zA-Z0-9]+)/contact/([a-zA-Z0-9]+)$ /locator/book/?id=$2 [L]

#Catch anything left with klvc in it
RewriteRule ^klvc/$ /locator/index.php [L]

Many thanks

petersen,

Oh, my! I won’t comment on the port assignment except to say “WHY!?!”

The point of interest to me is that the DocumentRoot of both the local.branch-x.com domains are the same - presumably the main domain’s DocumentRoot, also.

Therefore, all you need to do for the (leafless - no path/file) “branches” is to add BEFORE your other code (after RewriteEngine on):

RewriteCond %{HTTP_HOST} ^www\\.branch-(1|2)\\.com$ [NC]
RewriteRule ^$ http://www.parentcompany.com/klvc/klvc_store.php?klvc=branch-%1 [R=301,L]

Regards,

DK

I’ve got the port assignment as this is a local version. I’m running IIS on port 80 and Apache on 81.

With regards to the RewriteCond I guess it looks like I’ll need to refer to the domain name of the branch in the querystring.

Thanks for your help David.

Regards,

DK

Do I take it that your position as Apache Guru indicates a disliking of IIS :wink:

What I meant was that currently I’m matching the shortname of the site

branch-1 for branch-1.com
i-love-apache for i-love-apache.com

From what I understand, I would need the domain name in the querystring, rather than the shortname. The shortname is the name of the branch, with spaces removed and hyphenated. I guess it could just be the domain name, but some branches have several instances, with the same domain name so I need a way to refer to the specific branch.

petersen,

Hmmm, I think you’re right on about that (my first “spec” in selecting a host is Apache)!

No, the shortname is fine. I had no idea that you were using (testing) the alias but that’s just fine.

Regards,

DK

Thanks David.

Once this goes live, I’ll give you a nod so you can take a look in all it’s glory :wink: