LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-21-2012, 11:49 AM   #1
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Rep: Reputation: 1
Rewrite rule adding extra slash after URL


Hi,

I'm using the following rewrite rule to redirect example.com to www.example.com in apache.

Code:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Problem is, after redirecting to www.example.com it's adding an extra "/". So it's like "http://www.example.com//".

Help Please!

Last edited by moyorakkhi; 05-21-2012 at 12:27 PM.
 
Old 05-21-2012, 12:07 PM   #2
Doc CPU
Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 999

Rep: Reputation: 294Reputation: 294Reputation: 294
Hi there,

Quote:
Originally Posted by moyorakkhi View Post
I'm using the following rewrite rule to redirect domain.com to www.domain.com in apache.
are you attached to that company in any way? If not, please don't use domain names you don't own as arbitrary examples. That's why the example domains like example.com, example.net or example.org have been invented (see RFC 2606 for more details).

Quote:
Originally Posted by moyorakkhi View Post
Code:
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Problem is, after redirecting to www.domain.com it's adding an extra "/". So it's like "http://www.domain.com//".
Yes, because that's what your rule demands:
It says "Take 'http://www.domain.com/' and append the contents of $1".
And $1 contains the local part of the HTTP URL, which always begins with a slash - in this case just '/' for the root document. Leave the trailing slash in your RewriteRule away.

[X] Doc CPU
 
Old 05-21-2012, 12:28 PM   #3
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Doc CPU View Post
Hi there,



are you attached to that company in any way? If not, please don't use domain names you don't own as arbitrary examples. That's why the example domains like example.com, example.net or example.org have been invented (see RFC 2606 for more details).



Yes, because that's what your rule demands:
It says "Take 'http://www.domain.com/' and append the contents of $1".
And $1 contains the local part of the HTTP URL, which always begins with a slash - in this case just '/' for the root document. Leave the trailing slash in your RewriteRule away.

[X] Doc CPU

Thanks for the Tips regarding example.com.

After removing $ from the rules it worked! Thanks!
 
  


Reply

Tags
apache


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
handling %20 in url with apache rewrite rule jnyunt Linux - Server 3 08-09-2011 10:56 PM
rewrite rule for url change ravibhure Linux - Server 2 01-21-2010 09:12 PM
URL rewrite rule not working... vikram_cvk Linux - Software 1 12-03-2008 02:14 AM
rewrite rule base url apache2 sinister1 Linux - Software 3 11-23-2007 10:17 AM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration