SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: 301 redirect

  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect

    Why isn't this working?



    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress


    Redirect 301 http://www.utahlibertylaw.com/about.html http://www.utahlibertylaw.com/about-us/

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Why isn't this working?
    Dumb question ... but it's in a .htaccess file, right?

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Because you need to put the Rewrite statement before the # BEGIN WordPress block. Otherwise the WordPress block will find that it can serve the URL and the Rewrite statement after that will be ignored; putting the Rewrite before the WordPress block solves that.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is in the .htaccess file. Did you mean to say that I need the redirect before the wordpress block or have it like this?

  5. #5
    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)
    Rémon,

    Quote Originally Posted by ScallioXTX View Post
    Because you need to put the Rewrite statement before the # BEGIN WordPress block. Otherwise the WordPress block will find that it can serve the URL and the Rewrite statement after that will be ignored; putting the Rewrite before the WordPress block solves that.
    First, I've got to assume that you're referring to the Redirect statement, not the "Rewrite statement."

    Second, mod_alias is part of the Apache core so it makes no difference where it's located (other than to help humans reading the code) because core directives are processed before non-core (mod_rewrite) directives. That's simply not the problem.

    Brian,

    Quote Originally Posted by BrianBam View Post
    Why isn't this working?

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    Redirect 301 http://www.utahlibertylaw.com/about.html     http://www.utahlibertylaw.com/about-us/
    Obviously, you're not looked at any of the WP threads in this board.

    The problem you're having with the about.html => about-us/ redirection is that you're syntax is faulty. The syntax for the Redirect statement is
    Code:
    Redirect [status] URL-path URL
    ... where the [status] is optional (but should be included), the URL-PATH will not contain either the protocol (http://) or the {HTTP_HOST} (www.utahlibertylaw.com). The URL for the redirection must be absolute (/about-us/) or the complete (external absolute) URL (which you've done - albeit I'm not a fan of redirecting a file to a directory).

    As for WP's code:

    1. REMOVE the <IfModule> wrapper after testing. Not to do so is an abuse of the server (and should have you kicked off a shared server). It's such an egregious error that I have a standard rant for it:

    [rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).
    [/rant 4]

    Nothing personal ... but it'll help you remember.

    2. RewriteBase is designed to UNDO a mod_alias redirection. Where's the redirection? Do you really want to undo your about.html => about-us/? Remove this before it causes problems.

    3. I have no clue why WP added the RewriteRule ^index\.php$ - [L] statement as it's already handled by the RewriteCond %{REQUEST_FILENAME} !-f so I remove this, too.

    4. Finally, the . in the RewriteRule is demanding at least a single character in the URI. If there is none (only the domain is requested), then this should fail. I prefer to add a ? after the dot character to make it optional. In addition, since this code is already located in the DocumentRoot, there is no need for the / before index.php in the redirection.

    That's quite a list but I hope it helps.

    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


Tags for this Thread

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
  •