Solved

How to redirect URL using wildcard?

Posted on 2008-10-27
4
604 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now