Forum Moderators: phranque

Message Too Old, No Replies

Htaccess/Modrewrite Problem

         

CosaNostra

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

10+ Year Member



Hello,

i need help with htaccess/modrewrite, i've a forum i would want its only ssl (https) and all http redirect to https and [mydomain.tld...] redirct to [mydomain.tld....]

i have subdomains and subfolders normal the subdomains like "mysub.mydomain.tld" (subfolder: mysub)

RewriteCond %{SERVER_PORT} !=443
RewriteCond %{REQUEST_FILENAME} !/(_sub1¦_sub2)/
RewriteRule ^(.*)$ [mydomain.tld...] [R=301,L]

but the subdomains redirect to [mydomain.tld...]

anyone can help me?

jdMorgan

3:14 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try checking the requested hostname instead of the filepath:

RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} !^(sub1¦sub2)\.example\.com
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Jim

CosaNostra

3:29 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



Thanks Jim for Reply..

but not work when i go to "sub1.example.com" it force me to [example.com...]

And i want thats all non-www force to www (exclude the subs, there is www not requerid)

example:
MainDomain (my Forum): [example.com...] to [example.com...]
Subdomains: [sub.example.com...]

and i forgot to say.. thats the subdomains non-ssl is.. [sub.example.com...] cuz my ssl cert is only for one domain.

jdMorgan

9:29 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change the broken pipe "¦" character to a solid pipe character (from your keyboard) before use; Posting on this forum modifies the pipe characters.

Jim

CosaNostra

12:41 am on Dec 1, 2009 (gmt 0)

10+ Year Member



Thanks Jim for Reply..

ihave changed the pipe to solid, the first sub work (sub1.example.com) but the second sub not work, its redirect me to [example.com...]

/edit:

dont understand this and make me confuse.. the sub2 is a webmail subdomain, all other subs work but only this sub doesn work.

Thats the error

---
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@sub2.example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
---

But when i rename the htaccess btw disable it, the subdomain work o.O

jdMorgan

2:22 am on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No idea why it wouldn't work, unless you spelled "sub2" incorrectly or if the "sub2" subpattern contains non-Western characters or something.

You can 'break down' the RewriteCond into multiple lines if it make things any clearer:


RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} !^sub1\.example\.com
RewriteCond %{HTTP_HOST} !^sub2\.example\.com
RewriteCond %{HTTP_HOST} !^sub3\.example\.com
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

The second 500 server error indicates that your server encountered another (probably the same) error while attempting to serve your custom 500 error page for the first error. You should not declare and try to use a custom 500 ErrorDocument which depends on anything but the basic server function to work. If you cannot guarantee that, then you should not declare a custom 500 error page, but instead just use the server default error message; It's ugly, but it always works.

Jim