Call Us: 512.271.5221

Get your project started:

06
February
2018

Redirects for Joomla Experimental URL Routing

Htaccess redirectsAlthough I found a posted solution a few months ago for URLs with article ID only (https://www.mysite.com/category/1111-article), I had several different scenarios that were going to 404's.  Those were:

 

 

Links with category ID

https://www.mysite.com/11-category/article

https://www.mysite.com/11-category/1111-article

 

Links with regular, non ID numbers in alias

http://www.mysite.com/the-best-10-things

http://www.mysite.com/11-category/the-best-10-things

http://www.mysite.com/11-category/1111-the-best-10-things

 

Below is the condensed code that accounts for all vaiants. 

RewriteCond %{REQUEST_URI} (.*)\/(\d{1,}-|)(.*)\/(\d{1,}-|)(.*)
RewriteRule ^(.*)(\/)(.*) %1/%3/%5 [L,QSA,R=301]

 

You can test specific URLs against it using https://htaccess.mwl.be?share=27edebe3-4ed5-5519-b093-2646c2f5689e

 

Below are the rules broken out separately in case anyone needs to customize.   When I get some more time, I will write explanations.  If you find a link that does not properly redirect, please add it to the comments as I want to improve it.

 

### with CATEGORY ID and ARTICLE ID ###
RewriteCond %{REQUEST_URI} (.*)(\/)(\d{1,})(-)(.*)(\/)(\d{1,})(-)(.*)
RewriteRule ^(.*)(\/)(.*) %1/%5/%9 [L,QSA,R=301]

### with CATEGORY ID only ###
RewriteCond %{REQUEST_URI} (.*)(\/)(\d{1,})(-)(.*)(\/)(.*)
RewriteRule ^(.*)(\/)(.*)(\/)(.*) %1/%5/%7 [L,QSA,R=301]

### ARTICLE ID only ###
RewriteCond %{REQUEST_URI} ^(.*)/(\d+)-([^/]+)$
RewriteRule ^ %1/%3 [L,QSA,R=301]

 

Also, for working on code like this, online testers are invaluable since there is a lot of trial and error.

Regex Tester

.htaccess Test

 

Thanks to Andreas Karr for taking my rules and consolidating into one awesome rule.  This is another good reference for regex.

Categories: .htaccess, Search Engine Optimization

blog comments powered by Disqus

certified web designer

Get Started with YellowWebMonkey

Invalid Input

Invalid Input

Invalid Input

Joomla Certified Administrator