homepage Welcome to WebmasterWorld Guest from 54.243.17.133
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess more than 1 rule
Mister206




msg:4491913
 2:05 pm on Sep 6, 2012 (gmt 0)

Hi. Ive never understood how to write multiple rules in htaccess. Can someone help me please. Ive read all the threads and I just get lost when being explained how it all works.

My Current htaccess looks like this

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

# END WordPress

I need to add 1 rue to this. I am renaming my wordpress category base. The example I have is

RewriteEngine on
RewriteBase /
RewriteRule ^old_dir/(.*) http://www.example.com/new_dir/$1 [R=301,L]

Now my structure looks like this currently

http://www.example.com/blog/category/category-name/

I want it to be like this

http://www.example.com/blog/new-category/category-name/

Any help would be greatly appreciiates

[edited by: incrediBILL at 7:10 pm (utc) on Sep 6, 2012]
[edit reason] fixed code formatting [/edit]

 

g1smd




msg:4491934
 2:52 pm on Sep 6, 2012 (gmt 0)

Make sure you have the RewriteEngine and Options directives just once each and listed at the top.

You can have as many rules as you like.

You need to put rules that affect a small number of URLs first, so they get processed first instead of more generalised rules. The non-www/www rule is usually the last rule of the redirects.

After the redirects, add your rewrites. This should also be ordered from most specific to most general.

Use RewriteRule for your redirects and your rewrites. Don't use Redirect or Redirectmatch.

Each RewriteRule rule can have one or more RewriteCond conditions that precede it.

A RewriteCond condition applies only to the next rule that follows it. The condition is evaluated AFTER the left side of the rule has been evaluated.

Add a blank line after each RewriteRule so you can see what is going on.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved