SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Directory Redirect In Htaccess

    Hi,
    I am trying to do what I thought would be a basic redirect in htaccess but am having a lot of problems. Basically, I've changed my structure so that now for a category the permalink is http://www.soundsandcolours.com/travel instead of http://www.soundsandcolours.com/cont...bjects/travel/ so I am trying to create a Rewrite Rule to do the redirect. Is there any way to create a simple rule that will do this redirect for all of my categories? My attempt at trying to do the redirect for just the Travel directory is below but this wasn't working. I've also tried countless examples on forums and tutorials but can't seem to get it working right. Any ideas why?

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^content/subjects/travel(/.*)?$ /travel$1 [L,R=301][L,R=301]
    </IfModule>
    Thanks!
    Russ

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,155
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    You probably need to remove the duplicated tags -- [L,R=301][L,R=301] -- then you probably need to move the permalink redirect rule above all the index.php-related rules. At the moment, because your permalink rule comes after the index.php rules, Apache's internal URL will always be index.php by the time your permalink rule executes.
    "First make it work. Then make it better."

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeff, that works perfectly!

    Just one follow-up question though, if I wanted to redirect all directories that had a similar structure, would this work?

    RewriteRule ^content/subjects(/.*)?$ /$1 [L,R=301]

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,155
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    I haven't run any tests to check, but it looks about right.
    "First make it work. Then make it better."


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
  •