Forum Moderators: phranque

Message Too Old, No Replies

newbie problem with mod_rewrite and virtual hosting

mod_rewrite rewrites *.html and other files, but not dir/

         

Paymaan

8:35 am on Apr 12, 2005 (gmt 0)

10+ Year Member



Hi everybody,

I am new here, and I apologize if my problem seems too simple.

I am using a virtual hosting, so my only choice is .htaccess for rewriting URLs. As my hosting space is too big for me, I am trying to use it for hosting my other domain names.

I am trying with a few scripts and currently this is what I use:

---
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#RewriteLog rewrite.log
#RewriteLogLevel 9

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org [NC]
RewriteCond %{REQUEST_URI}!^/computer/
RewriteRule (.*) /computer/$1 [L]

# Prevent direct 'computer' type-in or link access
rewritecond %{THE_REQUEST} ^[A-Z]+\ (http://(www\.)?domain\.(org)(:[0-9]+)?)/(computer)/(.*)\ HTTP
rewriterule .* %1/%6 [R=301,L]

---

Yes I have copied it from somewhere in this list, but I have tried other types and got almost the same result.

First that I can not see any rewrite log on my server to be able to track the problem, so I've commented those lines out.

Then links are rewrite with this results (considering I am using domain.org, domain.org should be rewrited to domain.com/computer folder and the are html pages there, including index.html, and the domain everything is
hosted on is domain.com):

1) [domain.org...] : browser shows the 404 page not found, address bar remains unchanged (http://www.domain.org)

2) [domain.org...] same as above.

3) [domain.org...] shows the content of /computer folder correctly, as I desire.

4) [domain.org...] shows the contect of domain.com, images are not shown, URL in address bar remains unchanged. (this might be due my ISP's cache server, as another html file shows correctly).

I have read mod_rewrite guide and documents, 100s of this forum's posts, regex tutorial etc. but I am somehow mixed up as I can not log what is happening (any help on rewrite log?), so I appreciate if you help to understand the problem (most important to me) and then to resolve it?!

Paymaan.

jd01

7:28 pm on May 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Possibly redundant to another post, but... (lazy, don't want to read all 30 to find out)

Have you tried individual .htaccess files in each sub directory EG have your main .htaccess in the site root, but put an individual 'no index' redirect in the sub-folders?

(I actually use sub-folder .htaccess often, especially when moving pages, because then as requests for those pages slow, so does my server load.)

Just an idea.

Justin

Paymaan

11:57 am on May 4, 2005 (gmt 0)

10+ Year Member



My server adminsitrators gave me this final description:

The following is straight from the official documentation regarding mod_rew
rite:

"Unbelievably, mod_rewrite provides URL manipulations in per-directory
context, i.e., within .htaccess files, although these are reached a very
long time after the URLs have been translated to filenames."

I just can't understand why nobody else has experienced my problem. Maybe I am asking for something odd?! Nobody else in the world uses domain pointers and directories to host sites?!

Paymaan.

jd01

8:31 pm on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Payamaan,

Let me ask again... Have you tried using a .htaccess on a per directory basis as described in the documentation?

EG In the actual directory that you would like to display the index.html file have you tried the following:

RewriteCond %{REQUEST_URI} ^![^.]+\.[^/]+$
RewriteRule ^/?$ http://www.example.com/your-directory-here/index.html [R=301,L]

If not please try this. (I believe using this rule format, the condition is actually optional (redundant), so please try both with and without the condition.)

Justin

Paymaan

6:25 am on May 11, 2005 (gmt 0)

10+ Year Member



Sorry I haven't been noticed this last mail.

Anyway, I put your latest rules in the /computer directory, what happens is that it works very nice when I issue the [example.org...] but not for any following directories (which is obvious), maybe if the forwarding address (example.org/your-directory-here/index.html) gets generalized in a way it also considers and adds the additional directories (and when there is no trailing slashes) to the rule, it works for all subdirectories?

What about using the -d? I myself am very mixed with this mod_rewrite and not yet used to it, so I am not sure how I can use the -d flag.

Cheers,
Paymaan.

This 34 message thread spans 2 pages: 34