Gossamer Forum
Home : General : Perl Programming :

.htaccess question

Quote Reply
.htaccess question
I have the following in my .htacces file so that users can have the address http://our.homewithgod.com/account_name/. The sub domain our actually points to mansions_our which is in the main directory.

Everything works fine as long as they put a / at he end of the url. But if they type in http://our.homewithgod.com/account_name without the / at the end, the address in the browser address bar changes to http://www.homewithgod.com/mansions_our/account_name/.

What do I need to add to the code to make it add the / if they do not enter it, or to keep the address http://our.homewithgod.com/account_name/?



RewriteCond %{HTTP_HOST} [^.]*our\.homewithgod.com$
RewriteRule ^(.*)$ /mansions_our/$1




Jimmy Crow
http://www.homewithgod.com/
Quote Reply
Re: .htaccess question In reply to
Not 100% sure but try......

RewriteRule ^/(.*) http://our.homewithgod.com/account_name/$1 [L,R]



Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: .htaccess question In reply to
Thanks for the reply Paul.

I wanted to wait until the traffic slowed down before trying your suggestion. The directory account_name would have to be a wildcard. So I tried it without the account_name and none of the images on any part of the web site mapped correctly. They were all broken.

Also, the directory 'account_name' needs to be a wildcard.

I found this at apache.org http://httpd.apache.org/...sc/rewriteguide.html

If I am reading the Solution correctly, it seems to contain the snippet of code that I need, but I can't figure out how to incorporate it into my .htaccess.

URL Layout

Canonical URLs

Description:
On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent which URL the user supplied with the request he should finally see the canonical one only.

Solution:
We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and fix a missing trailing slash for /u/user.
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]


and

Trailing Slash Problem

Description:
Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then the server searches for a file named foo. And because this file is a directory it complains. Actually is tries to fix it themself in most of the cases, but sometimes this mechanism need to be emulated by you. For instance after you have done a lot of complicated URL rewritings to CGI scripts etc.

Solution:
The solution to this subtle problem is to let the server add the trailing slash automatically. To do this correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If we only did a internal rewrite, this would only work for the directory page, but would go wrong when any images are included into this page with relative URLs, because the browser would request an in-lined object. For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the external redirect!
So, to do this trick we write:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]




The crazy and lazy can even do the following in the top-level .htaccess file of their homedir. But notice that this creates some processing overhead.

RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]



Jimmy Crow
http://www.homewithgod.com/