1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Someone please enlighten me - 301 redirect issue

Discussion in 'Blogging' started by ShadeDream, Oct 19, 2013.

  1. ShadeDream

    ShadeDream Elite Member

    Joined:
    Nov 27, 2008
    Messages:
    2,209
    Likes Received:
    5,230
    Location:
    He who laughs last, laughs longest.
    Not sure if I'm not thinking clearly or what but I seem to be facing a 301 redirect issue on one of my sites.

    I've set up my site with a permalink of this structure:
    Code:
    /blog/%postname%/
    The "blog" directory/page does not exist and shows a 404. I therefore want to redirect any potential traffic to the root domain.

    The root domain contains the posts. I've set the permalink as per above to create a specific structure in case I want to make the root domain a static page in the future.

    My .htaccess looks like this:

    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
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^blog$ "http\:\/\/www\.example\.com\/" [R=301,L]
    
    Now, when I visit "http://www.example.com/blog" the 301 redirect does not work and I still get the 404 page.

    What the f**k?
     
  2. ShadeDream

    ShadeDream Elite Member

    Joined:
    Nov 27, 2008
    Messages:
    2,209
    Likes Received:
    5,230
    Location:
    He who laughs last, laughs longest.
    I'm still unsure WTF is wrong, I tried a different way and it worked great.

    Code:
    Redirect 301 /blog http://www.example.com
    Though this caused other issues, so I ended up using a php file for what I needed.

    I also couldn't get rid of the redirect until I cleared my cache.

    Not sure if the issue is with the web host or what, but this is the first time I've come across this.
     
  3. Asif WILSON Khan

    Asif WILSON Khan Executive VIP Premium Member

    Joined:
    Nov 10, 2012
    Messages:
    10,125
    Likes Received:
    28,564
    Gender:
    Male
    Occupation:
    Fun Lovin' Criminal
    Location:
    London
    Home Page:
  4. watsonovedades

    watsonovedades Senior Member

    Joined:
    Mar 10, 2011
    Messages:
    922
    Likes Received:
    233
    Location:
    Mexico
    why not leave the .htacces as it is and instead make the redirection on your cPanel
     
  5. ShadeDream

    ShadeDream Elite Member

    Joined:
    Nov 27, 2008
    Messages:
    2,209
    Likes Received:
    5,230
    Location:
    He who laughs last, laughs longest.
    That's the issue, the cPanel redirect does not work. I'm not sure if you've ever used it since you didn't notice this from the OP.

    The cPanel one does this:

    Code:
    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^blog$ "http\:\/\/www\.example\.com\/" [R=301,L]
    And it would not work.
     
  6. Asif WILSON Khan

    Asif WILSON Khan Executive VIP Premium Member

    Joined:
    Nov 10, 2012
    Messages:
    10,125
    Likes Received:
    28,564
    Gender:
    Male
    Occupation:
    Fun Lovin' Criminal
    Location:
    London
    Home Page:
  7. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    8,891
    Likes Received:
    7,493
    Occupation:
    ZLinky2Buy SEO Services
    Location:
    ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
    Home Page:
    Add this to your .htaccess

    RedirectMatch 301 /blog/(.+) /$1
     
    • Thanks Thanks x 1
  8. ShadeDream

    ShadeDream Elite Member

    Joined:
    Nov 27, 2008
    Messages:
    2,209
    Likes Received:
    5,230
    Location:
    He who laughs last, laughs longest.
    Thanks guys, the issue has now been solved. I've had a bit of an issue with the 301 being cached. :eek:
     
  9. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,649
    Likes Received:
    3,494
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
    OP, could you please list the solution?

    As I am thinking of doing sth similar :)

    Thanks iin advance dude!
     
  10. ShadeDream

    ShadeDream Elite Member

    Joined:
    Nov 27, 2008
    Messages:
    2,209
    Likes Received:
    5,230
    Location:
    He who laughs last, laughs longest.
    I'm not sure how you understood the issue I was having but sure.

    I basically wanted to use the root domain to display the posts while at the same time having a "/blog/%postname%/" permalink.

    The permalink worked great but because the "/blog" directory did not exist, any traffic that would visit the "/blog" directory directly would get a 404.

    The 301 redirect via .htaccess was causing me issues and would make the posts inaccessible, again a 404 error.

    So I created a "blog" folder within the "public html". I then created an "index.php" 301 redirect file and put it into the "blog" folder.

    This can be achieved through other means, but for what I needed this was good.