0

I would like to remove part of the url of my Joomla site and redirect to another url for example

www.example.com/xxx/yyy/zzz/FAQ

www.example.com/123/456/FAQ

to

www.example.com/FAQ

I'm very new to mod_rewrite in .htacesss

what RewriteRule can I write to achive this

thank you

  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Gonzalo Dec 14 '15 at 18:32

2 Answers2

0

Try this in root/htaccess

RewriteEngine On

 RewriteCond %{THE_REQUEST} /xx/yy/zz/([^\s]+) [NC]
RewriteRule ^ /%1? [NC,L,R]
  RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /xx/yy/zz/$1 [NC,L]

And the same rule can be used to rewrite /123/456/faq to /123/456/FAq , just change the rewrite target and the pattern in first Rewritecond.

$1 is part of the regex in rewrite rule, its the part matched between (.+) ,it contains uri.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Thank you for your answer, but what I actually need is turn "www.example.com/xxx/yyy/zzz/FAQ" into "www.example.com/FAQ. I want to remove "/xxx/yyy/zzz" (which can be anything) so if possible I would like to find a way to remove any string between ".com/" and "/FAQ" I think your answer is the opposite. – Peerapong Sutinrerk Dec 14 '15 at 20:04
  • Thank you Starkeen, I think I found the solution and will post it soon :) – Peerapong Sutinrerk Dec 15 '15 at 17:08
0

Thank you, after I tried I finally got it working

this is my solution

RewriteEngine On
RewriteRule ^.*/FAQ$ /FAQ [L,R=301]

by doing this I remove everything between the URL and FAQ

www.abc.com/SOMETHING/SOMETHING2/FAQ

and redirect the URL to

www.abc.com/FAQ

I also found a nice tool to test the mod_rewrite code http://htaccess.madewithlove.be/