0

I'm trying to redirect my website like example.com/anypage to www.example.com/anypage

This is what I'm using in my httpd.conf file

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^example.com [nocase]
RewriteRule ^(.*)         http://www.example.com/$1 [last,redirect=301]

This redirects the page to www.example.com//anypage

How do I remove the extra slash?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Unknown Coder
  • 783
  • 3
  • 12
  • 23
  • [mod_rewrite behaves differently when used in per-server/virtualhost and per-directory configuration](http://httpd.apache.org/docs/current/rewrite/tech.html): “In per-directory context (i.e., within `.htaccess` files and `Directory` blocks), […] the URL-path that mod_rewrite initially compares `RewriteRule` directives against is the full filesystem path to the translated filename **with the current directories path (including a trailing slash) removed from the front**.” – Gumbo Jan 19 '14 at 13:09
  • @Gumbo meaning I should use `http://www.example.com$1` as `RewriteRule`? – Unknown Coder Jan 19 '14 at 13:18
  • Either that, or you shouldn’t capture the leading slash. – Gumbo Jan 19 '14 at 13:25

1 Answers1

0

Try changing this line:

RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301]

to:

RewriteRule ^/(.*) http://www.example.com/$1 [last,redirect=301]

Jack Bonneman
  • 1,821
  • 18
  • 24