How to redirect URL using wildcard?

Posted on 2008-10-27
Medium Priority
Last Modified: 2012-05-05

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?

Question by:cwdo
  • 2
  • 2
LVL 27

Expert Comment

ID: 22816687
e.g. with
Redirect 301 /discussions/discussions/ http://www.example.com/discussions/

Open in new window


Author Comment

ID: 22816749
Thanks for the quick reply.

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


Note that this is on a Drupal site, so Drupal may be imposing some .htaccess restrictions?

Accepted Solution

cwdo earned 0 total points
ID: 22816885
Got it to work:

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

Expert Comment

ID: 22816918
It looks like that you're using mod_rewrite and it conflicts with one or some of your rules.


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

below the line
'RewriteEngine on', i.e. above the RewriteRuls from drupal.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question