Rewriting part of the url structure in htaccess

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
Forsh
Joomla! Explorer
Joomla! Explorer
Posts: 250
Joined: Sat Aug 20, 2005 3:05 pm
Location: 2029 Larimer St, Denver, CO 80205
Contact:

Rewriting part of the url structure in htaccess

Post by Forsh » Wed Apr 10, 2019 3:41 am

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/urlhere /tag/sunday-meetings

to

mywebsite . com /new/urlhere /tag/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 do any of these look like they might work?

Code: Select all

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


natecovington
Joomla! Explorer
Joomla! Explorer
Posts: 435
Joined: Tue Jul 29, 2008 11:54 pm
Location: NE PA
Contact:

Re: Rewriting part of the url structure in htaccess

Post by natecovington » Thu Apr 11, 2019 2:43 pm

I'd try to set up something like this in htaccess

RewriteRule ^old-page/(.*)$ /new-page/$1 [R=301,NC]
I am available for professional Joomla support, consulting, and custom work:
www.covingtoncreations.com

Forsh
Joomla! Explorer
Joomla! Explorer
Posts: 250
Joined: Sat Aug 20, 2005 3:05 pm
Location: 2029 Larimer St, Denver, CO 80205
Contact:

Re: Rewriting part of the url structure in htaccess

Post by Forsh » Thu Apr 11, 2019 5:20 pm

natecovington wrote:
Thu Apr 11, 2019 2:43 pm
I'd try to set up something like this in htaccess

RewriteRule ^old-page/(.*)$ /new-page/$1 [R=301,NC]
I'll give it a shot and see if it works, appreciate the answer. If I can figure out how to do this one thing I would sit here all week and do this too all of my broken links. I can do a single 301 of a full url in .htaccess but all of the broken urls are in the middle of the url. (leaving out the entire link as not to be spammy)

OLD: .com/vehicle-donation-colorado/tag/aurora-aa-meetings

NEW: .com/component/tortags/tag/aurora-aa-meetings

Those are the actual urls and the bold is what changed affecting thousands of urls. :eek:


Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”