Can someone help me write this mod_rewrite rule?

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Ok, you can call me a noob, and I could possibly get flamed, but I can't figure this one out for the life of me. I don't know why mod_rewrite gives me so much trouble.

Ok, so here's what I'm trying to do. I want to remove the "www" from the URL, but only on a subdomain.

I have this rule, which removes it from the whole domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

and that works ok. But in this instance, I only want to remove it from one directory and it's sub directories.

For example:

I want www.mydomain.com/catalog to be rewritten to http://mydomain.com/catalog

If anyone could help I would be greatly appreciative. I've spent like 3 hours trying everything I could to get this to work with no luck.
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
I would be more then happy to even take any alternative methods. I just for the life of me can not get this to work....
 

Website Rob

Well-Known Member
Mar 23, 2002
1,501
1
318
Alberta, Canada
cPanel Access Level
Root Administrator
Your rewrite rule is correct and working as it should. Sounds like the problem is that 'catagory' is a directory for a Shopping Cart script. If it is, you only need to remove the 'www' from your "config" file.


i.e., for Zen Cart in 'includes/configure.php' and 'admin/includes/configure.php'

// Define the webserver and path parameters
// HTTP_SERVER is your Main webserver: eg, http://www.yourdomain.com
// HTTPS_SERVER is your Secure webserver: eg, https://www.yourdomain.com

change to

// Define the webserver and path parameters
// HTTP_SERVER is your Main webserver: eg, http://yourdomain.com
// HTTPS_SERVER is your Secure webserver: eg, https://yourdomain.com


Use whatever 'config' file is used by your Shopping Cart.
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Your rewrite rule is correct and working as it should. Sounds like the problem is that 'catagory' is a directory for a Shopping Cart script. If it is, you only need to remove the 'www' from your "config" file.


i.e., for Zen Cart in 'includes/configure.php' and 'admin/includes/configure.php'

// Define the webserver and path parameters
// HTTP_SERVER is your Main webserver: eg, http://www.yourdomain.com
// HTTPS_SERVER is your Secure webserver: eg, https://www.yourdomain.com

change to

// Define the webserver and path parameters
// HTTP_SERVER is your Main webserver: eg, http://yourdomain.com
// HTTPS_SERVER is your Secure webserver: eg, https://yourdomain.com


Use whatever 'config' file is used by your Shopping Cart.
Correct, the rewrite rule does work, but for the whole domain. I just want it to work for the catalog directory only.

It's a custom cart system the customer wrote, so if someone hits the www version of the site, then goes to the cart, they are getting the mismatch of the name on the certificate.

However, this mod-rewrite the way I have it is affecting other parts of his site and causing them to not work right. It's a huge site, so I just want to remove the www from the cart's directory.

Thanks
Damion
 

astopy

Well-Known Member
Apr 3, 2003
166
0
166
cPanel Access Level
Root Administrator
Try:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^catalog/(.*)$ http://mydomain.com/catalog/$1 [R=301,L]