?
Solved

Help with mod_rewrite 301 appending extra /

Posted on 2009-04-21
2
Medium Priority
?
238 Views
Last Modified: 2012-05-06
I have the following mod_rewrite rule :
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^example\.com\.au$ [NC]
    RewriteRule ^(.*)$ http://example.com.au/$1 [R=301,L]

The problem is when it redirects http://anything.example.com.au/ to http://example.com.au/ it appends an extra / so the user ends up at http://example.com.au/

I know I can use no slash before $1:
    RewriteRule ^(.*)$ http://poshlingerie.com.au$1 [R=301,L]

But I'm not sure if this is the best way to do it.
0
Comment
Question by:TotallyMe
2 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 24202058
> I know I can use no slash before $1:

There's no problem with that; this is common practice if the rule is used in th httpd.conf. Another way would be to strip the slash from the matched pattern:
RewriteEngine On
# if you're looking for a direct match, use the lex eq. operator instead of a regular expression
RewriteCond %{HTTP_HOST} !=example.com.au [NC]
RewriteRule ^/(.*)$ http://poshlingerie.com.au/$1 [R=301,L]

Open in new window

0
 

Author Comment

by:TotallyMe
ID: 24203841
That works great :) I really like the simplicity of  !=example.com.au
And I'm using ^/(.*)$ just incase my URLs went back to a single slash and stopped working.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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). #…
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.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 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