The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can someone help me write this mod_rewrite rule?

Discussion in 'General Discussion' started by noimad1, Oct 12, 2007.

  1. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    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.
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,482
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    You shouldn't need to use this, for that.
     
  3. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Ok, thanks for the help. Mind telling me what your secret is?
     
    #3 noimad1, Oct 12, 2007
    Last edited: Oct 13, 2007
  4. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    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....
     
  5. Website Rob

    Website Rob Well-Known Member

    Joined:
    Mar 23, 2002
    Messages:
    1,506
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    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.
     
  6. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  7. astopy

    astopy Well-Known Member

    Joined:
    Apr 3, 2003
    Messages:
    165
    Likes Received:
    0
    Trophy Points:
    16
    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]
     
Loading...

Share This Page