Forum Moderators: phranque

Message Too Old, No Replies

How to remove trailing slash in domain etc

so no trailing slash and even wrong # of w's

         

danv

10:47 am on May 18, 2006 (gmt 0)

10+ Year Member



The .htaccess rewrite code adds a trailing slash to my domain. I am trying to remove that *and* get a person to type in a number of prefixes like: www or [www...] or even a 'w' or 2 more or less then required and the URL gets re-written to: http://www.example.com

thanks.

------- .htaccess Code -----------
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

JoaoJose

11:18 am on May 18, 2006 (gmt 0)

10+ Year Member



www.yoursite.com will always resolve to [yoursite.com...]

Is w.yoursite.com resolving to anything?

The only way i see this hapening is if you have a subdomain named "w" but I don't even know if this is possible.

jdMorgan

9:37 pm on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you already have wild-card subdomains set up in DNS and in your server config so that all variants resolve to your server, then the following modification will handle all subdomain variant requests:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

In plain words, if the requested domain is not the canonical domain, redirect to the canonical domain.

Do not end-anchor the domain name pattern in the RewriteCond unless you add "(:80)?$" or "(:[0-9]{1,5})?$" to the end of the pattern. Otherwise your rule will fail if a user or proxy appends a port number to the domain (It is perfectly valid to do so).

[added] Neither this code nor the code you posted above will "add a trailing slash" to your domain name. However, if UseCanonicalName is set to "on" in your server config file, and if the server name or DocumentRoot is misconfigured (with a trailing slash on it), then it might appear to do so. [/added]

Jim