Forum Moderators: phranque
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.
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
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.
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
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.