Results 1 to 11 of 11
  1. #1

    Apache Rewrite rules

    With this whole no-www thing going on. I've decided to have a look at whether I can do this for my domains.

    Instead of writing a

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
    RewriteRule ^(.*)$ h77p://domain.com/$1 [R=301,L]

    for every single domain I'd like to do this for across all domains as standard. I'm not too hot on rewrite rules and have in the past avoided them cos of the complexities. But I'd like to get this done, and no silently do it, but reflect the URL difference in the webbrowsers address bar too.

    Can someone please pretty please help me? I'll give cookies

  2. #2
    Join Date
    Dec 2005
    Location
    Internet
    Posts
    1,337
    Can someone please pretty please help me? I'll give cookies
    Give the cookies first, then we'll try

    Just create the .htaccess with the above rules under the skeleton directory, so that all it will be copied to all the newly created domains. Otherwise, you have to specify it in httpd.conf file.

  3. #3
    ::Hands out chocolate cookies::

    I think you missed the point. I want to add a few lines to httpd.conf to do this as a wildcard to domains. I don't want to have a rewrite rule for every single domain on my webserver. There are no cpanels on my server as I like full power control over the system :-D

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
    RewriteRule ^(.*)$ h77p://domain1.com/$1 [R=301,L]
    RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
    RewriteRule ^(.*)$ h77p://domain2.com/$1 [R=301,L]

    That'd just get messy with 100 domains being served. I'd like to write one that is generic across all domains on the server.

  4. #4
    Join Date
    Dec 2006
    Location
    Charlotte NC
    Posts
    155

    Lightbulb

    Give this a try

    Code:
    # domain.com -> /var/www/domain.com/public_html
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^([a-z0-9-.]+)$
    RewriteCond  /var/www/%1/public_html -d
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
    RewriteRule  ^([a-z0-9-.]+)/(.*) /var/www/$1/public_html/$2
    
    # www.domain.com -> /var/www/domain.com/public_html
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^www\.([a-z0-9-.]+)$
    RewriteCond  /var/www/%1/public_html -d
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
    RewriteRule  ^www\.([a-z0-9-.]+)/(.*) /var/www/$1/public_html/$2
    Caro.net :: Engineered Hosting
    Engineered Hosting solutions including Cloud, Dedicated, Colocation, and Managed Services.

  5. #5
    Gah stupid forum, it splatted my post cos I had a smilie in it!

    All I'm after is "www mydomain.com/index5.php" forwarded to "mydomain.com/index5.php", and this change reflected in the end users web browser so they bookmark the new url. Directory structure is very rigid and in place already so no need for /var/www stuff.... almost put a smilie just!

    And again post rejected....

  6. #6
    Join Date
    Dec 2006
    Location
    Charlotte NC
    Posts
    155
    How about this

    Code:
    # domain.com -> www.domain.com
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^([a-z0-9-.]+)$
    RewriteCond  ${lowercase:%{HTTP_HOST}}  !^www\.([a-z0-9-.]+)$
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
    RewriteRule  ^([a-z0-9-.]+)/(.*) www\.$1/$2
    Caro.net :: Engineered Hosting
    Engineered Hosting solutions including Cloud, Dedicated, Colocation, and Managed Services.

  7. #7
    Sadly that doesn't work. For example try both www ubersoft.info and ubersoft.info

  8. #8
    Join Date
    Dec 2006
    Location
    Charlotte NC
    Posts
    155
    My apologies! I have forgotten the flag to create the URL redirection. Please try the following example:

    Code:
    # domain.com -> www.domain.com
    RewriteCond  ${lowercase:%{HTTP_HOST}}  ^([a-z0-9-.]+)$
    RewriteCond  ${lowercase:%{HTTP_HOST}}  !^www\.([a-z0-9-.]+)$
    RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
    RewriteRule  ^([a-z0-9-.]+)/(.*) http://www\.$1/$2 [R=301,L]
    Caro.net :: Engineered Hosting
    Engineered Hosting solutions including Cloud, Dedicated, Colocation, and Managed Services.

  9. #9
    I don't suppose you have MSN or IRC? Might be faster

  10. #10
    Incidentally my vhost.conf for ubersoft.info is

    Code:
    <VirtualHost *:80>
        ServerAdmin   [email protected]
        ServerName    ubersoft.info
    
        RewriteEngine On
        RewriteOptions inherit
        RewriteCond  ${lowercase:%{HTTP_HOST}}  ^([a-z0-9-.]+)$
        RewriteCond  ${lowercase:%{HTTP_HOST}}  !^www\.([a-z0-9-.]+)$
        RewriteRule  ^(.+)  ${lowercase:%{HTTP_HOST}}$1  [C]
        RewriteRule  ^([a-z0-9-.]+)/(.*) http://www\.$1/$2 [R=301,L]
    
        suPHP_Engine on
        suPHP_UserGroup apache apache
    
        CBandUser myLimiter
    
        ErrorDocument 404 /errors/404.html
    
        DocumentRoot "/var/www/ubersoft.info/www/htdocs"
        <Directory "/var/www/ubersoft.info/www/htdocs">
            Options Indexes FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    
    </VirtualHost>

  11. #11
    http://www.pastebin.it/2716

    I've put my httpd.conf, and one of the vhost files there for your glance over.

    http://www.ubersoft.info does not forward to http://ubersoft.info though. (Not even the reverse happens)

Posting Permissions

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