Results 1 to 4 of 4

Thread: Need help with mod_rewrite

  1. #1
    polren6 NNTP User

    Default Need help with mod_rewrite

    My objective is to have all visitors going to mysite.com be forwarded to www. mysite.com
    Same with https. I'm attempting to have it achieved with the mod_rewrite in the /etc/apache2/default-server.conf with a weird result. It works well for https, however it does not for http. Would anybody be able to point me in the right direction?

    here is the code:

    Code:
    RewriteCond %{HTTPS} on
     RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
     RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
     RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
     RewriteCond %{HTTPS} Off
     RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
     RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
     RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

  2. #2
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: Need help with mod_rewrite

    polren6 wrote:
    > My objective is to have all visitors going to mysite.com be forwarded to
    > www. mysite.com
    > Same with https. I'm attempting to have it achieved with the
    > mod_rewrite in the /etc/apache2/default-server.conf with a weird
    > result. It works well for https, however it does not for http. Would
    > anybody be able to point me in the right direction?
    >
    > here is the code:
    >
    >
    > Code:
    > --------------------
    > RewriteCond %{HTTPS} on
    > RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
    > RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
    > RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
    > RewriteCond %{HTTPS} Off
    > RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
    > RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
    > RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
    >
    > --------------------


    i probably should remain silent (because i know nothing about apache
    configuration--nor why you would want to 'forward' once inside, rather
    direct to the same IP before)....BUT, can't you do what you wish by
    setting the DNS records for the domain mysite to have both mysite.com
    and www.mysite.com resolve to the same IP??

    that is the way i do it,

    DenverD

  3. #3
    polren6 NNTP User

    Default Re: Need help with mod_rewrite

    Thanks DenverD, I appreciate it.

  4. #4
    Join Date
    Jun 2008
    Location
    Finland, European Union
    Posts
    1,879

    Default Re: Need help with mod_rewrite

    Now this is most likely stupid to ask but did you remember to enable rewriting on the default host as well as the SSL vhost?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •