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.

redirect rules

Discussion in 'General Discussion' started by bobmane, Jul 5, 2011.

  1. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    i asked my host tech support to redirect about 50 old urls


    like

    domain.com/old-page1.html to domain.com permanent

    domain.com/old-page2.html to domain.com/new-page.html permanent

    etc...

    they first put in a broad redirect so that anything

    domain.com/sdfb,asfb
    domain.com/waiuerylrhaw.khakha.kgn

    would redirect to

    domain.com/

    [i think, but not sure] the broad redirect interfered with some of my code and caused some errors, so I asked them to use a different approach redirecting only my specified urls.


    they told me to manually do it my self in cPAnel

    so I did, one at a time entered all the redirect

    now in my htaccess file all the rules are there



    RewriteCond %{HTTP_HOST} ^doamain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.doamain.com$
    RewriteRule ^articles\/popup\/Gut5\.html$ "http\:\/\/domain\.com\/" [R=301,L]


    but alot of them do not work



    my host said it is because I have too many rules


    any solutions of how to do this right?
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,480
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    I'm not aware of any limits to the number of redirects, but if one does not work, we could assume it was added incorrectly. There's lots of threads about using redirects on these forums, and even more on google you might look into for tips on why some of those you've added are not working as expected.

    If you've added any rules manually to the .htaccess file, I'd start there and remove those. Adding via cPanel should alert you to a problem with one as its added.
     
  3. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    I am adding them in cPanel with cPanel Redirect tool and cPanel is not warning me about anything.


    Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting


    also, it seem the format written by cPanel is wrong? how can that be?

    this is what it write to my file when i use the setting in the image:

    RewriteCond %{HTTP_HOST} ^example.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
    RewriteRule ^Pages\/Basic\/Tools\.html$ "http\:\/\/example\.com\/" [R=301,L]
     

    Attached Files:

  4. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    I am adding them in cPanel with cPanel Redirect tool and cPanel is not warning me about anything.


    Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting


    also, it seem the format written by cPanel is wrong? how can that be?

    this is what it write to my file when i use the setting in the image:

    RewriteCond %{HTTP_HOST} ^example.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
    RewriteRule ^Pages\/Basic\/Tools\.html$ "http\:\/\/example\.com\/" [R=301,L]
     
  5. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,480
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Can you be more specific as to what you feel is wrong with the format? I see no mention of this in your image:
    RewriteRule ^Pages\/Basic\/Tools\.html$

    I do see the word HUSTLE in all caps, could that be an issue? Not sure.
     
  6. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    i am not a coder only a beginner so i dont know.

    i was told this by someone else:

    i wrote:

    this is what cPanel writes if i tell it i want to send example.com.hustleharder/ (or any file in the folder) to example.com :

    RewriteCond %{HTTP_HOST} ^example.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
    RewriteRule ^hustleharder\/index\.html$ "http\:\/\/example\.com\/" [R=301,L]

    they wrote:

    If that is a direct cut-and-paste, then cPanel is bonkers.

    1: You never escape anything in the target. Otherwise it will try to send you to the literal url
    http\:\/\/example\.com\/
    with all those slashes.
    2: You do not need to escape slashes / at all, ever. (Unless you are working in JavaScript or related languages.) Some RegEx environments don't especially care if you escape things that don't need to be escaped, but Apache is picky.

    someone else also said i do not need:


    RewriteCond %{HTTP_HOST} ^example.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.example.com$
     
  7. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,480
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    This is an example just generated by cPanel that works as expected:


    RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^testing\/index\.html\/?(.*)$ "http\:\/\/domain\.com\/$1" [R=301,L]

    You'll note the only difference is I ticked the "Wild Card Redirect" option.


    I did a second test redirecting from deeper in the file system as well:

    RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^testing\/tester\/test\/index\.html\/?(.*)$ "http\:\/\/domain\.com\/$1" [R=301,L]

    This works as expected as well.
     
  8. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    could you please look at the htaccess file and see if there is something wrong because i tired what you said and it did not work.
     
    #8 bobmane, Jul 6, 2011
    Last edited by a moderator: Jul 6, 2011
  9. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,480
    Likes Received:
    203
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    You've got a lot going on in this file. For now to test, I suggest you rename that file to .htaccess.txt to kill it.

    Now go back into cPanel > Redirects and try adding any redirect you like. Then test the redirects, I believe you'll find they now work.

    Next, add back in, one section at a time of your old htaccess.txt and test your redirect after each change. When the redirect breaks you'll know which one it was. Much of this IMHO, is not even needed and/or is duplicated.
     
  10. bobmane

    bobmane Member

    Joined:
    Jul 5, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    that sounds like a good approach and i will do it and post back the results



    "Much of this IMHO, is not even needed and/or is duplicated. "


    I can tell you this...

    this is for a magento website so the htaccess code might be quite different than a normal website...but...there may in fact be some modifications that were made to that file that are not needed (not by me but by someone who was working on the site)
     
Loading...

Share This Page