homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Content Management
Forum Library, Charter, Moderators: ergophobe

Content Management Forum

How to change Joomla non SEF urls in index to SEF
How to change Joomla non SEF urls in index to SEF

 11:47 am on Jan 27, 2012 (gmt 0)

I'm switching a J1.5 site from non-sef URLs to SEF and want to 301 redirect the query string external article links to the default SEF equivalent. (globalconfig is SEF on, Use .htaccess).

The external non-SEF links are formatted like:


And the SEF equivalent of that URL is:

Any assistance would be appreciated.



 11:59 am on Jan 27, 2012 (gmt 0)

You could do this with a very long list of RewriteRules configured as redirects in .htaccess, but it would be difficult to maintain.

A better solution is to use a single RewriteRule to internally rewrite all of those requests to a PHP script and the PHP script look up the new URL and use the HEADER directive to issue the 301 redirect.

You have two choices as to how you look up the new URL. You either store the old and new URLs as value pairs in a PHP array or you store them in a database table.

Either way, this is a large amount of work and any SEF solution worth installing should already have just such functionality already included.

There is one glimmer of hope for a simple solution. IF *all* of the "parts" of the new URL can be found some place in the old URL, then you might be able to use a single simple RewriteRule to redirect all such requests without needing a lookup table.

You'll need a RewriteCond that looks at THE_REQUEST and pulls out relavent parts of the query string to re-use in the new URL. The RewriteRule RegEx pattern will need to match the path (and ONLY the path) part of the URL request and the target URL will be built both from static parts (protocol and domain for starters) and the captured parts of the original query string. The target URL will end with a question mark to suppress the re-addition of query string data and the rule will need the [R=301,L] flags.


 1:54 pm on Jan 27, 2012 (gmt 0)

I'm not very fluent with modrewrite or regex however if possible I would like to avoid adding a component/plugin to solve it.

All of the article SEF and non-SEF URLs have the same format:

index.php? | DISCARD
view=article | DISCARD
id=###:article title | /###-article-title-
catid=##:cat title | cat-title/

Which becomes /cat-title/###-article-title

What would the condition / rewrite look like?



 2:17 pm on Jan 27, 2012 (gmt 0)

As you are going to need to maintain your code, it is vital that you understand how it works. Redirecting from parameters to static-looking URLs is a question that comes up several times each week so there are literally thousands of prior code snippets here in this forum.

You have made a very good start by defining exactly what you want the code to do. Many people overlook this step and proceed to coding before they have fully worked out what the problem to be solved actually is.

I've already listed all of the elements that you'll need to work with, you'll just need to assemble them along with the correct RegEx patterns to extract the data to use as backreferences.

Be aware that
THE_REQUEST begins GET /<somestuff>?<someparams> HTTP/1.1 and the first part can be matched with ^[A-Z]{3,9}\ /

The pattern
=([^&]+) can be used to extract a parameter value into a backreference.

Let's see your best shot after some thorough research...

travelin cat

 3:19 pm on Mar 22, 2012 (gmt 0)

A much easier solution is to upgrade to Joomla 2.5, you should do this for many reasons anyway. In 2.5 there is a component called "Redirect" built in that allows you to do this, and much more, directly from within the backend of Joomla.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Content Management
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved