How to redirect URL using wildcard?

Hello,

I'm trying to 301 redirect all pages from 1) to 2):

1) example.com/discussions/discussions/bla-bla
2) example.com/discussions/bla-bla

In essence removing the second "discussions" directory.

How would I achieve this in .htaccess?

Thanks,
Alex
cwdoAsked:
Who is Participating?
 
cwdoConnect With a Mentor Author Commented:
Got it to work:

RewriteRule ^discussions/discussions/(.*)$ http://www.example.com/discussions/$1 [R=301,L]
0
 
caterham_wwwCommented:
e.g. with
Redirect 301 /discussions/discussions/ http://www.example.com/discussions/

Open in new window

0
 
cwdoAuthor Commented:
Thanks for the quick reply.

I added your suggestion to .htaccess, but it doesn't quite work as intended.  It redirects to:

http://www.example.com/discussions/bla-bla?q=discussions/discussions/bla-bla?

Note that this is on a Drupal site, so Drupal may be imposing some .htaccess restrictions?
0
 
caterham_wwwCommented:
It looks like that you're using mod_rewrite and it conflicts with one or some of your rules.

Add

RewriteRule ^discussions/(discussions/.*) http://www.example.com/$1 [R=301,L]

below the line
'RewriteEngine on', i.e. above the RewriteRuls from drupal.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.