Forum Moderators: phranque
When a user enters a URL in the address window by hand without the trailing slash, the browser's address window displays his location incorrectly.
CORRECT BEHAVIOR:
If the user enters:
[word.domain.com...]
or
[word.domain.com...]
Then he is taken to the "/blue/index.htm" page, and his address window correctly shows:
[word.domain.com...]
INCORRECT BEHAVIOR:
If the user does not include the trailing slash (hand entry into address window):
[word.domain.com...]
Then his address window will resolve to the following:
[domain.com...]
Here are the mod-rewrite rules from my .htaccess file (note - I barely understand this; I just hacked this together from reading a support doc my webhosting company offered, and then reading up on some Apache stuff):
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for word.domain.com
RewriteCond %{HTTP_HOST} word.domain.com$
RewriteCond %{REQUEST_URI} !/word/
RewriteRule ^(.*)$ /word/$1
Anyone know how to fix this so that a URL entered without the trailing slash will resolve as follows?
[word.domain.com...]
Unfortunately, I don't see a direct way to influence which hostname mod_dir uses for this redirect. It must be some other configuration detail of the server that makes it work as expected on my server but not on yours.
Using "RewriteRule ^(.*)$ /word/$1/" might actually cause more problems than it solves, as the "$1" may well be a file name instead of a directory, and you don't really want to add the slash in that case.
I tried changing the last rewrite rule to:
RewriteRule ^(.*)$ /word/$1/
...but it causes a 404 error.
I poked around the Apache documentation, and I tried adding the following:
UseCanonicalName off
...based on what I read here:
[httpd.apache.org...]
...but this caused every request to the server to return a "500 Internal Server Error" error code.
Anyone got any further ideas on this?
If I don't get this fixed, will it cause me any spidering problems with Google or any of the other SEs?
If I were to setup separate IP numbers, that would solve the problem.
It doesn't seem that the spiders would have a problem with this, since they are following the correct syntax full-paths on mywebpages. The only time this issue comes up is when someone hand enters a URL, or trims the URL.
So I am going to hang loose with this defect, and I think I'll be fine.
Thanks for the discussion.
Thanks for the suggestion. I tried adding those lines, with no success. Perhaps I didn't add them correctly (keep in mind I am low-tech on this one).
Here's what I tried:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for word.domain.com
RewriteCond %{HTTP_HOST} word.domain.com $
RewriteCond %{REQUEST_URI} !/word/
RewriteRule ^(.*)/([a-zA-Z]+)$ $1/$2/
RewriteRule ^/([a-zA-Z]+)$ /$1/
What I did above is I swapped in your 2 lines for last RewriteRule line in my code.
Is this what you were suggesting?
This one didn't work.
In testing your rule by leaving out the trailing slash, it appears to resolve by moving up one level in the directory heirarchy and adding the www host back in. The results of the test were a little screwy, partly due to my directory structure being a little hard to keep track of.
[httpd.apache.org...]
RewriteEngine on
# Rename in HTTP mode:
RewriteCond %{HTTP_HOST} !^word.domain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTPS} "off"
RewriteRule ^/(.*) [word.domain.com...] [L,R]
# Rename in HTTPS mode:
!^word.domain.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTPS} "on"
RewriteRule ^/(.*) [word.domain.com...] [L,R]