LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Rewrite rule adding extra slash after URL (http://www.linuxquestions.org/questions/linux-newbie-8/rewrite-rule-adding-extra-slash-after-url-946174/)

moyorakkhi 05-21-2012 11:49 AM

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!

Doc CPU 05-21-2012 12:07 PM

Hi there,

Quote:

Originally Posted by moyorakkhi (Post 4684105)
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 (Post 4684105)
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

moyorakkhi 05-21-2012 12:28 PM

Quote:

Originally Posted by Doc CPU (Post 4684117)
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!


All times are GMT -5. The time now is 05:53 AM.