Forum Moderators: phranque

Message Too Old, No Replies

redirect to subfolder with .htaccess

         

gpatch

2:37 pm on Nov 24, 2009 (gmt 0)

10+ Year Member



I read this topic [webmasterworld.com...]

and I make follow jdMorgan answer

my directory structure is :

/index.php
/web/index.php

After I follow answer it not work

but if i delete index.php both director it work !

but i need to use /web/index.php Can help me ?

thank for answer.

jdMorgan

5:27 pm on Nov 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the code as a basis for discussion.

Thanks,
Jim

gpatch

7:20 pm on Nov 25, 2009 (gmt 0)

10+ Year Member



I use this.

RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteRule ^(([^/]+/)*[^./]+)$ http://www.example.com/$1/ [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com
RewriteCond %{REQUEST_URI} !/domainfolder/
RewriteRule ^(.*)$ domainfolder/$1 [L]

it can redirect if in folder /domainfolder not have index.php
but I need use index.php in /domainfolder/index.php

jdMorgan

2:56 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try changing the Options to

Options +FollowSymLinks -MultiViews

If that does not help, please be very specific about what URL you type, what result you see in your browser, what messages (if any) you see in your server error log, what you expected to see, and how what you see differs from what you expected to see. Please remember that we cannot see what is working correctly and what is failing, or how it is failing -- You have to tell us.

Jim

gpatch

6:14 pm on Nov 29, 2009 (gmt 0)

10+ Year Member



it still not work

Apache error log nothing and Apache access log show this

110.164.x.x - - [30/Nov/2009:01:07:43 +0700] "GET / HTTP/1.1" 200 33 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)"

I type url as example.com and www.example.com but it not work both.

I explain my file in both directory

my directory structure is :

/index.php
/web/index.php

inside file :

$ cat index.php
Not Redirect
$ cat web/index.php
Redirect Success

it mean if url is forwarding my webpage must show Redirect Success if not it shot Not Redirect

thank for your answer

jdMorgan

2:23 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this code located in example.com/.htaccess or is it in a subdirectory?

Do you have any other URL-rewriting code -- such as more mod_rewrite code or Alias or ScriptAlias directives in either a .htaccess file above this one or in the server configuration files (perhaps added by control panel or by installing a blog, forum, or shopping cart script package)?

Jim

gpatch

2:45 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



my .htaccess is in root directory and i not have any rewrite rule

please see this

$ pwd
/home/example.com/htdocs
$ cat .htaccess
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteBase /

RewriteRule ^(([^/]+/)*[^./]+)$ http://www.example.com/$1/ [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com
RewriteCond %{REQUEST_URI} !/web/
RewriteRule ^(.*)$ web/$1 [L]
$

gpatch

1:49 pm on Dec 9, 2009 (gmt 0)

10+ Year Member



I'm waiting answer.

nobody see this post :(

jdMorgan

2:50 pm on Dec 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry -- sometimes it's easy to miss the fact that a thread has been updated...

Are you on Apache 2.x? If so, try adding


AcceptPathInfo off

You can also comment-out each of the two rule-sets one-at-a-time, to see if they are interfering with each other. It's much easier to test one rule at a time.

Your requests both returned a 33-byte response. So what was on that 33-byte page? Did you do a View->Page-source in your browser to check?

Jim

gpatch

3:30 pm on Dec 9, 2009 (gmt 0)

10+ Year Member



I'm using apache 2.x and try to add AcceptPathInfo off and then restart apache.

It still not redirect. --

Can see following message from header check

=============================================================

Requesting www.example.com .. Ok
Reply received (reply time: 141 ms)
-----------------------------------
HTTP/1.1 200 OK
Date: Wed, 09 Dec 2009 15:09:02 GMT
Server: Apache/2
Vary: Accept-Encoding
Connection: close
Content-Type: text/html

Not Redirect

=============================================================

If I change .htaccess rule by comment two line RewriteCond
header it show this

=============================================================

Requesting www.example.com .. Ok
Reply received (reply time: 156 ms)
-----------------------------------
HTTP/1.1 500 Internal Server Error
Date: Wed, 09 Dec 2009 15:22:42 GMT
Server: Apache/2
Vary: Accept-Encoding
Content-Length: 669
Connection: close
Content-Type: text/html; charset=iso-8859-1

=============================================================

jdMorgan

6:06 pm on Dec 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, at least the 500-Server Error proves that your code is executing... :)

But according to the last version of the code you posted, you should be requesting "www.example.com.com" -- That is the hostname required by your first RewriteCond.

Make sure that hostname pattern in the RewriteCond is correct.

Jim

gpatch

6:32 pm on Dec 9, 2009 (gmt 0)

10+ Year Member



oh yes !

Hair shielding the mountains.

It Idioms in thai language mean Easy, but have no idea. (mean I'm)

thank you so much jdMorgan

jdMorgan

11:06 pm on Dec 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yin dee maak!
[Very glad (that it worked)]

Jim