1

I know how to create rewrite rules in Apache but what I don't know is how to rewrite a previously rewritten url.

This is an old URL

/boats-for-sale/fairline-squadron-55/1280

and I need to redirect to

/brokerage/boats-for-sale/boat/1280=-fairline-squadron-55

How is this possible? I assume I can create a rule that will do this form all rules that fall in this format

closed as off-topic by Stephen Ostermiller Jul 27 '18 at 14:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are specific to one website are discouraged because they are unlikely to help future visitors. Examples include individual website reviews for SEO purposes and general website troubleshooting. See the How to Ask page for help improving this question." – Stephen Ostermiller
If this question can be reworded to fit the rules in the help center, please edit the question.

  • "rewrite a previously rewritten url" - in the same request? Are you using .htaccess? "I know how to create rewrite rules" - I'm wondering how this is different to any other rewrite/redirect? (Although, by the sounds of it, you need a redirect, not a rewrite.) What problem are you having specifically? Please include your current config and any attempts you have tried. – MrWhite Jul 24 '18 at 9:24
  • Why rewrite twice when you can do it right the first time? Modify your original rule. – closetnoc Jul 24 '18 at 14:19
  • I can't because it's Joomla that created the SEF urls in the first place and they're not stored in the .htaccess file. I needed to add some redirects as the url has now changed and Google would have cached them. – Peter Griffin Jul 25 '18 at 10:03
  • This situation looks very specific to your site and wouldn't be applicable to anybody else. – Stephen Ostermiller Jul 27 '18 at 14:34
1

I can't because it's Joomla that created the SEF urls in the first place and they're not stored in the .htaccess file. I needed to add some redirects as the url has now changed and Google would have cached them.

It sounds like you just need a regular redirect. The URL has changed, so you want to redirect from the old to the new for SEO. (It's unclear what you mean by "rewrite existing rewritten url" - as @closetnoc mentioned in comments, you would ideally "correct" the first rewrite in this case. But the SEF URLs in Joomla are not "rewrites" in this sense.)

Any redirect you implement in .htaccess will need to go before the Joomla front-controller.

It's not clear how "generic" you need this to be (how many URLs are we dealing with?), but to literally redirect the URL as stated, you could do something like:

RewriteRule ^boats-for-sale/fairline-squadron-55/1280 /brokerage/boats-for-sale/boat/1280=-fairline-squadron-55 [R,L]

(NB: That =- in the substitution does look a bit out of place?)

For a more generic solution, maybe something like:

RewriteRule ^(boats-for-sale)/([^/]+)/(\d+) /brokerage/$1/boat/$3=-$2 [R,L]

This will redirect the above URL and any URL of the form /boats-for-sale/<anything>/<number> to /brokerage/boats-for-sale/boat/<number>=-<anything>.

Change the R (temporary 302) to R=301 (permanent) only when you have confirmed it's working OK - to avoid caching issues.

Not the answer you're looking for? Browse other questions tagged or ask your own question.