Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Rewriting Website URLs

Discussion in 'General Discussion' started by denverdonate, Apr 9, 2019.

  1. denverdonate

    denverdonate Registered

    Joined:
    Apr 9, 2019
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    1
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Part of my URL structure changed can I rewrite part of a URL in htaccess instead of updating thousands of urls one-by-one by hand?

    mywebsite . com /old/component /tag/colorado-sunday-meetings
    to
    mywebsite . com /new/component /tag/colorado-sunday-meetings

    If it was this one url I could 301 it but it's thousands of urls with that 1 change in the url structure.

    I have been looking for examples online but I don't know if any of these work and where I would modify if so.
    Code:
    ---------------------------------------------------------------------
    ---------------------------------------------------------------------
    Removing the Query String
    RewriteRule ^/url /url?
    
    Adding to the Query String
    Keep the existing query string using the Query String Append flag, but add var=val to the end.
    RewriteRule ^/url /url?var=val [QSA]
    
    Rewriting For Certain Query Strings
    Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.
    RewriteCond %{QUERY_STRING} val
    RewriteRule ^/url1 /url2
    
    Modifying the Query String
    Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.
    RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
    RewriteRule /path /path?%1other_val%2
    ---------------------------------------------------------------------
    ---------------------------------------------------------------------
    
     
    #1 denverdonate, Apr 9, 2019
    Last edited by a moderator: Apr 10, 2019
  2. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    5,734
    Likes Received:
    436
    Trophy Points:
    233
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. denverdonate

    denverdonate Registered

    Joined:
    Apr 9, 2019
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    1
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Just want to make sure I understand with the wildcard redirect....

    1. This redirect is above everything in htaccess.
    2. I redirect from the beginning to the end of a URL and require the exact structure such as https : // webitewhateveritis . com/blah/blah to https : // webitewhateveritis . com/blah/newblah

    if my structure is https : // webitewhateveritis . com/blah/blah/blah.jpg I don't go to /blah.jpg only as far as the url changes.

    Ok, I'll give that a shot right now...
     
    cPanelLauren likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice