1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Moving Rewrite Commands from .htaccess to httpd.config

Discussion in 'Apache' started by pecanpie, Oct 10, 2009.

  1. #1
    Hello, I'm unable to move the following commands from .htaccess to httpd.config without causing weird problems;

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysitename\.com
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule (.*) http://www.mysitename.com/$1 [R=301,L,QSA]

    Must the above commands be altered somehow to work in httpd.config?

    I really want to eliminate the .htaccess file so the server does not have to check before each page load.

    If somebody could show me the proper commands, it would help so much.

    Thank you
     
    pecanpie, Oct 10, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First, tell us what the actual error(s) is/are when you move this to a .conf file, also check your apache error logs and turn on RewriteLog so you can see verbosely where you might have gone wrong, thanks.
     
    szalinski, Oct 12, 2009 IP
  3. pecanpie

    pecanpie Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for replying.

    Redirects wouldn't work;
    a) 301's failed to execute when clicking banners
    b) And failed to redirect properly when typing in non-www versions of url's
     
    pecanpie, Oct 15, 2009 IP
  4. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Those directives look fine to me which indicates that it must be something else outside these lines that is causing it not to work.

    Two things I can see from what you have pasted:
    1. If someone hits your site using anything other than sitename.com, they won't be redirected.
    2. If your website is only listening on another port, they won't be redirected.

    If you are using NameVirtualHost and you have other domains on the same server, make sure you have a ServerAlias directive of sitename.com as well as a ServerName of www.sitename.com. Also, make sure these directives (both the ServerAlias and the RewriteRules) are in the VirtualHost container.

    You can change this line:
    
    RewriteCond %{HTTP_HOST} ^mysitename\.com
    
    Code (markup):
    to this:
    
    RewriteCond %{HTTP_HOST} !^www\.mysitename\.com
    
    Code (markup):
    which is useful if this vhost is the default vhost.

    You can drop the %{SERVER_PORT} line entirely unless there are people hitting your website on another port that you don't want redirected.

    I noticed that you are using [L] in your rewrite. If you have another rewrite above that one that matches normal queries, has an [L] and doesn't have a [R] or [R=301] then it will never get to the lines you have given us.
     
    Ladadadada, Oct 18, 2009 IP