Forum Moderators: phranque

Message Too Old, No Replies

.htaccess problem , please help me!

.htaccess can't work ,i don't know why?

         

heamon

2:38 am on Dec 23, 2006 (gmt 0)



Now , I want to do this: if I visit http://one.example.com, the url can visite http://www.example.com/one/index.html realy

now,it's i have writen:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[a-z0-9\-]+\.example\.com$
RewriteRule ^/(.*)$ /%{SERVER_NAME}/$1
RewriteRule ^/([a-z0-9\-]+)\.example\.com/(.*)$ /$1/$2 [L]
RewriteRule ^.*$ /index.php [L]

I writen it in the httpd.conf ,it can work but I written in the .htaccess it didn't work,why?

the log error is:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

please help me,thank you!

<Use example.com please
See Forum Charter [webmasterworld.com]>

[edited by: tedster at 4:21 am (utc) on Dec. 23, 2006]

jdMorgan

5:21 am on Dec 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In .htaccess:

RewriteEngine on
RewriteCond %{ENV:rwdone} !^yes$
RewriteCond %{HTTP_HOST} !www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9\-]+)\.example\.com
RewriteRule (.*) /%2/$1 [E=rwdone:yes,L]

In .htaccess, mod_rewrite behaves recursively, so some mechanism must be used to prevent the rule from rewriting its own output repeatedly, avoiding an 'infinite' loop. Here, I create and use a variable called "rwdone", meaning "rewrite already done" for this purpose.

So, the first RewriteCond prevents repeated rewriting if rwdone has already been set to "yes".

The second RewriteCond prevents rewriting requests for the "www" subdomain.

The third RewriteCond captures the subdomain name into local variable %2, and also allows (but does not require) the subdomain name to be preceded by "www." in case of type-in addresses like "www.subdomain.example.com".

The RewriteRule then takes the requested URL path in $1 and prepends the subdomain name from %2, forming the rewritten URL-path. It also sets the environment variable "rwdone" to "yes" so that this rule will not be applied on the next mod_rewrite pass through your .htaccess code.

Thanks to member rkrause for the tip on avoiding "subdirectory obscuration."

In .httpd.conf, the code can be much simpler:


RewriteCond %{HTTP_HOST} !www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9\-]+)\.example\.com
RewriteRule [b]^/([/b].*)$ /%2/$1 [L]

Jim

heamon

5:38 am on Dec 23, 2006 (gmt 0)



thank you!

but when i use the code:

the error is:
[Sat Dec 23 13:33:35 2006] [error] [client 219.***.133.105] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

why?

and i upload the .htaccess file to the space, the rewrite can't work,

the *.example.com all go to the root/index.html why?

[edited by: jdMorgan at 5:45 am (utc) on Dec. 23, 2006]
[edit reason] Obscured personal IP address [/edit]

jdMorgan

5:44 am on Dec 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Based on this and your other posts, I'd say that your server has a configuration problem that needs to be looked into... The code I posted came off a live server, so it does work.

Jim