SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect using .htaccess (one webpage to another)

    Hi,

    I am trying to redirect one web page to another using a 301 redirect. The code I am using is:

    Code:
    RewriteEngine On
    redirect 301 /link1.htm http://www.sitename.com/link2.htm
      redirect 301 /link3.htm http://www.sitename.com/link4.htm
    The 301 redirect is not working at the moment.

    What is wrong with this code? Can someone help me, please?

    Kind regards,

    Matt.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    There's actually nothing wrong with that code. I copy-pasted it, and it works as expected. The real problem must be elsewhere.
    "First make it work. Then make it better."

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Matt,

    Since this is NOT mod_rewrite (the Redirect family of directives belong to mod_alias), I'd first remove your RewriteEngine on statement. Then, if this is in the DocumentRoot's .htaccess, I'd remove the leading / from your Redirect statements. THEN it will work properly.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is still not working.

    My complete .htaccess file looks like this:

    Notice I am redirecting based upon capitalisation.

    Code:
      redirect 301 Gatso.htm http://www.speedcamerasuk.com/gatso.htm
      redirect 301 Truvelo.htm http://www.speedcamerasuk.com/truvelo.htm
    
    <IfModule mod_expires.c>  
      # Enable expirations
        ExpiresActive On 
        # Default directive
        ExpiresDefault "access plus 1 month"
        # My favicon
        ExpiresByType image/x-icon "access plus 1 yearÓ
        # Images
        ExpiresByType images/gif "access plus 1 month"
        ExpiresByType images/png "access plus 1 month"
        ExpiresByType images/jpg "access plus 1 month"
        ExpiresByType images/jpeg "access plus 1 month"
        # CSS
        ExpiresByType text/css "access 1 monthÓ
        # Javascript
        ExpiresByType application/javascript "access plus 1 year"
        # compress text, HTML, JavaScript, CSS, and XML
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
        # remove browser bugs
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        Header append Vary User-Agent
      </p>
    </IfModule>

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Looks like you have a stray </p> in there. That shouldn't be there, and it's causing a syntax error.

    Then you'll also have to add leading slashes on the old URL you're redirecting from. (The Redirect directive matches against the request path and always begins with a slash.)

    Code:
      redirect 301 /Gatso.htm http://www.speedcamerasuk.com/gatso.htm
      redirect 301 /Truvelo.htm http://www.speedcamerasuk.com/truvelo.htm
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

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