Help with htaccess. Please help

Hi guys,

I tried to learn the htaccess tricks to make good URLs but im not able to understand anything.

I’m not very good at this. So please bear with me. Thanks.

URL : www.mysite.com/?company=cisco
I want to make it as : www.cisco.mysite.com

URL : www.mysite.com/?company=cisco&?cat=switches&?subcat=wired
I want to make it as : www.cisco.mysite.com/switches/wired

I saw for an option with my host, and i see only basic redirection. It asks me for the url to redirect and url to redirect to.

I can edit the php .ini file. But dont know what i need to edit.

Hi coder,

Welcome to the SitePoint forums :wave:

First of all, do you have a subdomain [noparse]www.cisco.mydomain.com[/noparse]? If you don’t than that’s a DNS problem and not something Apache can help you with.
Of course if the DNS exists you still need a VirtualHost on there.

Okay, assuming you have that, what you need to understand here is that for what you’re asking to do you need to update all the links on your website. For example if there is a link to [noparse]www.mysite.com/?company=cisco[/noparse] on your website you need to change that to [noparse]www.cisco.mysite.com[/noparse] and use Apache to internally serve [noparse]www.mysite.com/?company=cisco[/noparse] when [noparse]www.cisco.mysite.com[/noparse] is requested.

php.ini is of no use here I btw; you need to create an .htaccess file for Apache to do what you want. I suggest you start by reading this tutorial and come back if you have any specific questions :slight_smile:

Thanks for your reply!

My host gives me unlimited subdomians.

And i was wrong about the htaccess edit thing.
I can create a new htaccess file in my directory and edit it the way i desire.

I haven’t started the site yet. But i have it all ready to be launched.

For example if there is a link to www.mysite.com/?company=cisco on your website you need to change that to www.cisco.mysite.com and use Apache to internally serve www.mysite.com/?company=cisco when www.cisco.mysite.com is requested

Maybe i was not able to ask the question properly, but this is what i want to do.

Can you help me with that ?

Okay, then you need to make sure the subdomain(s) you want exist and point the correct directory; i.e. the directory your main website lives in.

Well, I can’t help you with the first part (replace all the links in your code), that’s completely up to you. As for Apache serving different content than requested I can help you with that, but please take a look at that tutorial I sent you first. It contains a lot of information and covers almost everything you would ever like to do with .htaccess. Of course if you can’t find what you’re looking for, or are confused about something, don’t be afraid to ask :slight_smile:

Thanks a lot for your reply mate.

I dont have any directories for the names of the companies(cisco). The names are names of companies in the companies table in mysql.

I will read the link you gave and follow it.

Appreciate your reply, really.

Thanks again.

But you do need those subdomains to exist, otherwise it wouldn’t make sense linking to them, now would it? :slight_smile:

You could set this up with a wildcard DNS and mass virtual hosting, but most shared hosting providers don’t allow this. Or do you have a dedicated server / VPS or something?

No dedicated server/vps. Will check wid my host if they support wildcard DNS.

AND mass virtual hosting … :slight_smile:

Rémon/777,

Actually, Apache does have a “Dynamically configured mass virtual hosting” but that’s not likely to be enabled.

As for how to handle the requests, using subdomains like you’ve suggested will mean that each has its own subdirectory and mod_rewrite code will have to be included in each (and EVERY) subdomain to get redirected back to the main domain’s subdirectory (although I have to ask why go UP one physical directory level).

A better way MIGHT be to PARK the subdomain ON the main domain and share all the files - just keep the differentiation between subdomains using the query string. If using Apache’s “Dynamically configured mass virtual hosting,” that would merely fall into place.

Regards,

DK

I checked with my host.
i have attached an image for the wildcard option i have.

What do i put there?

Well it says “Leave the wildcard empty if you want all traffic to go to the same target as your primary domain.”

Going from that I’d say you don’t have to fill in anything :slight_smile:

Have you tested if the subdomains work? i.e. create a very basic test.html, upload it, and see if you can request it from [noparse]www.cisco.mysite.com/test.html[/noparse] for example?

Thanks for your reply.

I created a folder. Named it as cisco and copied the index file there.
Created a session for company called cisco.

I had to copy few other files too to get the site function properly. But you see its a lot of labor if i decide to add more companies.

Is there any other way to achieve the desired result??

I m using php btw.

Thanks.

777,

Actually, that’s a REAL blessing for you! However, you don’t need the subdirectory for the original question:

URL : www.mysite.com/?company=cisco
I want to make it as : www.cisco.mysite.com

URL : http://www.mysite.com/?company=cisco...&?subcat=wired
I want to make it as : www.cisco.mysite.com/switches/wired

All you need to do is to use mod_rewrite to capture the (non-www) subdomain and create a query string to assign it to the company key (YOU create the link in the NEW format, mod_rewrite converts that to something Apache can serve).

As for the switches/wired “specification,” capture those (before the other RewriteRule) and redirect to your DirectoryIndex with those keys assigned the values captured from the path. Of course, check that the path does not resolve to a file or directory before redirecting!

Regards,

DK