Forum Moderators: phranque

Message Too Old, No Replies

www to non-www and password-protected directories problem

problem is with password-protected directory when using redirect

         

dc006

9:18 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



Hi folks,
I have been searching like crazy and finally found topic in this forum, covering similar issue Iam heaving, but is closed so Iam posting new. I hope somebody can help me here.

I have osCommerce website installed in directory /ceske-slovenske-potraviny/
and because I have two domains .com and .co.uk I wanted to to use RewriteCond to handle redirects.
So I want all request (even www) to go to subdirectory of main domain example.co.uk/ceske-slovenske-potraviny/

The RewriteCond I come up with seem to work okay, but the problem is with password protected directory example.co.uk/ceske-slovenske-potraviny/protected/

When RewriteCond is in place and I try to access protected directory Iam redirected to page about cookies (which in fact replace 401 page).

my .htaccess (in root)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$ [NC]
RewriteRule ^(.*)$ http://example.co.uk/ceske-slovenske-potraviny/$1 [L,R=301]
I have tried RewriteOptions inherit mentioned in other topic, bus this doesnt work.
(trailing slash at the end also daesnt helped)

Any ideas please?
Thank you

[edited by: jdMorgan at 10:32 pm (utc) on Aug. 31, 2007]
[edit reason] example.co.uk [/edit]

jdMorgan

10:32 pm on Aug 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know what you intended the "RewriteCond %{HTTP_HOST} ^.*$" line to do, but it won't do anything, since the ".*" pattern will match any hostname, even a blank one.

It looks like your real problem is that you have coded an infinite loop, because there is nothing to stop the rewrite from executing recursively.

Try this, which will stop recursion:


Options +FollowSymLinks
RewriteEngine on
#
# If not already rewritten to subdirectory
RewriteCond %{REQUEST_URI} !^/ceske-slovenske-potraviny/
# rewrite all requests to the c-s-p subdirectory
RewriteRule (.*) http://example.co.uk/ceske-slovenske-potraviny/$1 [L,R=301]

You may also want to create and declare proper custom error pages for 401, 403, 404, 410, and 500 errors, for example:

ErrorDocument 500 /my_server_error_document.html

Also, please do not post your own domain name unless you would like this thread to outrank your own site in searches for for your domain! Use example.com or example.co.uk

Jim

dc006

11:30 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



Many thanks for reply.
Your suggested redirect works well but this still prevent me from accessing protected directory example.com/ceske-slovenske-potraviny/potected

this is output from header check:
HTTP/1.1 301 Moved Permanently =>
Date => Fri, 31 Aug 2007 23:28:07 GMT
Server => Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a
WWW-Authenticate => Basic realm="Halusky Admin"
Location => http://example.com/ceske-slovenske-potraviny/401.shtml
Connection => close
Content-Type => text/html; charset=iso-8859-1

dc006

11:41 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



401 actually means "you need to log on", silly me.
So the header checker can't pass through.

But anyway I dont even get login promt when trying to access protected folder.