Solved

How to redirect URL using wildcard?

Posted on 2008-10-27
4
607 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:cwdo
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

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

Open in new window

0
 

Author Comment

by:cwdo
ID: 22816749
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
 

Accepted Solution

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

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

Expert Comment

by:caterham_www
ID: 22816918
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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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