10 awesome .htaccess hacks for WordPress

by Jean. 251 Comments -

.htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things. In this article, let’s see how .htaccess can help you with your WordPress blog, for both security,functionnality and usability.


When editing or modifying the .htaccess file of your WordPress blog, make sure to always have a backup that you can restore in case of something went wrong.

1 – Redirect WordPress RSS feeds to feedburner with .htaccess

Which blogger doesn’t use feedburner? Sure, feedburner is a very nice service, allowing you to know how many people suscribed to your rss feeds. The only problem is that you must edit your theme files to manually change the rss url. Happilly, there’s a nice hack, using .htaccess, which will make you save a lot of time!
Don’t forget to modify line 6 before applying this code!

# temp redirect wordpress content feeds to feedburner
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
 RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
 RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.feedburner.com/catswhocode [R=302,NC,L]

Source: How to redirect WordPress rss feeds to feedburner

2 – Remove /category/ from your WordPress url

By default, WordPress category permalinks are displayed that way:


As you can see, the category in the url is pretty useless. Here’s how to remove it:
First backup your .htaccess file. Then, open it and append the following line:

RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

Once saved, your categories pages will be displayed like this:


Source: How to remove category from your WordPress url

3 – Using browser cache

A very good way to optimize your blog loading time is to force the use of the browser cache. This code will not improve your blog loading time directly, but it will save some work to the server by sending a 304 not modified status when the requested element haven’t been modified.

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"

Source: Comment accelerer le temps de chargement de votre blog

4 – Compress static data

Do you know that it is possible to send compressed data to the visitors, which will be decompressed by the client? This code will definitely save you (and your visitor) bandwidth and reduce your pages weight.

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

5 – Redirect Day and name permalinks to /%postname%/

The first thing to do is to login to your WordPress admin, go to Settings → Permalinks and select custom. Fill out the field with /%postname%/.
Your permalinks will now look like the ones on this blog:


Now we got to redirect all backlinks using the old permalinks structure to the new permalink structure. To do so, you’ll have to edit the .htaccess file, located in WordPress root directory.
Paste the following line in your .htaccess:

RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.domain.com/$4

Allright! You just changed your permalinks structure without loosing any backlinks!
Source: Redirect day and name permalinks to postname

6 – How to: Deny comment posting to no referrer requests

Are you sick and tired about the daily amount of spam comments received? Sure, there’s akismet, but here’s a little .htaccess trick to prevent spammers posting on your blog. The fact is that most spammers uses bots comming from nowhere. This code will look for the referrer (the page from where the commentator come from) and will deny commenting if the commentator try to access the wp-comments-post.php file without directly comming from your blog.
Just change the line 4 and specify your blog url there.

RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Source: How to deny comment posting to no referrer requests

7 – Redirect visitors to a maintenance page

When you’re upgrading your blog, or making theme/design changes, it isn’t a good idea to let people see your blog being tweaked, sometimes with design or code problems, or even worst, security gaps.
The solution is to design a nice “maintenance page” and temporarily redirect your visitors to that page until you finished the maintenance.
Replace maintenance.html (line 2) by the page you’d like to redirect your visitors, and the IP adress on line 3 by your own ip.
Note that a 302 redirection is used, to avoid search engines indexing the maintenance page instead of your real homepage!

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /maintenance.html [R=302,L]

Source: Comment faire une page d’accueil pour les internautes

8 – Protect your WordPress blog from hotlinking

Hotlinking is the use of an image from one site into a web page belonging to another site. Many bloggers are hotlinked, and have their bandwidth used on another websites. This very helpful code will protect your WordPress blog from hotlinking.

RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

Source: How to protect your WordPress blog from hotlinking

9 – Allow only your IP adress on the wp-admin directory

Excepted the case of a collaborative blog, only you should be allowed to visit the wp-admin directory. If you have a static IP, this code will do the job.
All you have to do is to enter your static IP adress on line 8. Note that you can add more IPs if needed, by creating a new line with: allow from xx.xx.xxx.xx inside.

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
order allow, deny
deny from all
allow from xx.xx.xx.xx

Source: Protecting the WordPress wp-admin folder

10 – Banning a WordPress Spammer With .htaccess

You know it, spam is very annoying. In the case of a particular person/bot spamming you, you can easily avoid it by blacklisting the IP.
Simply replace the IP adress on line 3 by the spammer’s IP. You can add more spammers by creating a new line with deny from xxx.xx.xxx.xxx inside.

<Limit GET POST>
order allow,deny
deny from
allow from all

Source: The easiest way to ban a WordPress spammer

More posts about htaccess

Share this article


Comments (251) - Leave yours

  1. Plantain said:

    8 – Protect your WordPress blog from hotlinking

    It will be necessary to try necessarily, and that in manual each time to change names of files tires, at the same time and protection against theft of a content.
    Thanks for the information

  2. Martin Fister said:

    This is a great list. You do a great job with your blog of really digging into deep aspects of developing a wordpress site and it really has helped me with my blog. I might try and change some of these things.

  3. Silver Firefly said:


    Thanks for this article, it’s going to be really useful for me, in fact – essential! I’ve dugg this article.

    In response to Comment #7, plugins are bloat. I’d prefer not to use plugins if possible.

  4. Allan Clark said:

    re: #8 (hotlinking), we had a competitor stealing our images. In such cases, the options are:
    1) refuse foreign references, as this solution does
    2) redirect to offensive image to hasten the takedown (immature, funny, but without goatcxe, lacking “oomph”)
    3) redirect to an advertisement for our site

    I opted for #3, I redirected to a lighter-weight image of the site to bring in more clicks. Also, considered swapping out my own reference to that image (only one local ref) and making a permanent redirect for the original reference, with the idea that the discussion plus the 301-redirect to my content actually improves SEO around that subject — the foreign hotlink costs me less bandwidth, but brings in traffic and SEO ranking :)

  5. Kaveh said:

    Awesome post.. thanks man! just a quick question though. Where should I copy these codes and how can i find this file that you mentioned? Im trying to use the hotlinking code you posted here.

    thanks again…

  6. mcd said:

    Tried the “Remove /category/ from your WordPress url” and it didn’t work. Should the code be placed in the .htaccess file in the blog/root folder or elsewhere?

  7. Wordpress Themes said:

    I’ve always been sorta scared to touvh the htaccess file, but I realized its fine. Just to back it up.

    Anyway, nice post, I like the one with feedburner, probably the most popular one.

  8. Raju said:

    superb post!! bookmarked and tweeted :) But I particularly don’t like the first hack. it defeats the purpose of feed structure of WordPress.

  9. 10个WordPress的.htaccess技巧(强烈推荐) at E-space said:

    [...] 对于Apache服务器,使用.htaccess文件可以进行很多相关网络服务访问的配置。而以下的10个技巧则专门针对WordPress所进行的设置,推荐大家参考使用: 参考原文:10 awesome .htaccess hacks for WordPress [...]

  10. Zulfikar said:

    Great post very informative. Imma wimp when it comes to messing with the .htaccess but I’v learnt somethings which am gona impelent. Thanks for the advice n tips.

  11. links for 2009-03-20 said:

    [...] 10 awesome .htaccess hacks for WordPress (tags: wordpress hacks htaccess) This entry was posted in Delicious. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL. « links for 2009-03-19 [...]

  12. 考拉 said:

    10 awesome .htaccess hacks for WordPress…

    通过 Apache çš„ .htaccess 实现:重定向 Feed 地址,去除分类链接中的 /category/,浏览器缓存,压缩静态数据,重定向日期格式的链接地址为 postname 格式,阻止没有 referrer 来源链接的垃圾评论,定….

  13. Netarhia said:

    Nice collection of tips. Still, have you tried #4 yourself? It seems not to work (checked with YSlow), components still aren’t gziped.
    As for #6, unfortunately, it’s really easy to set the referrer and user agent, from any server-side script, loads of bots are that advanced. Did you notice any improvement with it?

  14. designtick.com said:

    10 awesome .htaccess hacks for WordPress…

    .htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things. In this article, let’s see how .htaccess can help you with your WordPress blog, for both security,functionnality and usability….

  15. Marketing Newb said:

    @ Maigret – removing category won’t matter unless you want to rank for that word :)

    Re #3 – is this required if you’re using the WP Super Cache plugin? It seems to do client side caching as well as server side. Not sure though.

  16. Catrin W said:

    Excellent wordpress hacks collection. I think everyone should at least implement those security hacks, as you never know when your blog will come on hacker’s mind.

  17. Listen To Hip Hop Music said:

    This is a very solid article. Its utilization to redirect wordpress rss feeds to feedburner is genius. I also like the idea of using .htaccess to ban spammers. That definitely is going to come in handy!

  18. AutoQuoter said:

    Super Article!

    On our site we have comments turned off, however in a dashboard you can still see the huge list of spams trying to get in via wp-comments-form.php and mostly from auto insurance sites, since we’re in that business. Hopefully we put the stop on that.

    Thank you so much, I already add the lines to my .httacess,

  19. Rick said:

    Excellent article. I was not aware you could do so much in the .htaccess file. I build wordpress sites almost exclusively. Good to know now how much flexibility I have in the .htaccess file.


  20. John Hoff - WpBlogHost said:

    Yeah but why would you ever want to use a plugin when there is no need.

    Plugins increase load time of your site and also pose possible security issues to your blog. Last week, someone tried to hack our blog using a security hole in the wp-adverts plugin. We don’t use that plugin, however.

    Whenever you can do something without a plugin, especially if it’s through .htaccess, that’s the way to do it.

  21. Alex Schleber said:

    Excellent collection, already tweeted/sent this to everyone I know.

    Re: 2) there is some value to your categories being identified as such to Google, same for Tags if you use them (which I hope you do, ideally with SimpleTags plugin which rules over WordPress’ native tag handling).

    Re: 5) nice trick, of course one should set this up in the way you describe from the beginning…

    Re: 6) I’ve found the YAWASP Plugin to catch 99% of spam via a very simple yet genius method that doesn’t require captchas and doesn’t have the overreach problems that Akismet has (I have Akismet turned off in fact).

  22. Lokale Gryfino said:

    Looks you’ve done a great job on .htaccess. I’d like to warn everyone – try it first before you put in on online server. Or backup your previous copy if you’re not 100% sure what you’re doing.

  23. Martin Fister said:

    I hadn’t even put two and two together on the rss feeds. Way to make the most out of it by redirecting to feed burner. This was a great list and I appreciate the suggestions. I hope to see some more soon!

  24. Sire said:

    In regards to the feedburner hack do you just replace the http://feeds2.feedburner.com/catswhocode portion with our own code?

  25. Stop Smoking Weed said:

    Thanks for the hacks. With regard to #7, can I use it redirect to another site (e.g. http://abc.com and how should I rewrite the code below

    RewriteCond %{REQUEST_URI} !/maintenance.html$

    Is this correct?

    RewriteCond %{REQUEST_URI} !abc.com$

  26. John Hoff - WpBlogHost said:

    Just remember though, if you stop hotlinking to images on your site you may be denying people a way to find your site. I get traffic from people searching Google and Yahoo Images.

    Toronto Plastic Surgeon
    See my previous comment. Plugins can slow down the load time of your blog and also provide possible security holes. I’ve been on the WP forums for awhile and there are a number of people’s blogs which have been hacked due to security issues with some plugins.

    .htaccess is always the best way to do things. It’s read before your website is even visited.

  27. bewegaleri said:

    yeah, i agree with John Hoff. sometimes hotlinked image can drive me some traffics. I don’t care about bandwidth because i host my files in Google (blogspot) :)

  28. Plaques said:

    Fantastic! The category removal from the directories has stumped me. This question might get me railed but it is possible to have an htaccess file in multiple directories on the site correct? I have only use WP for stand alone installations, not to hang on a website.

  29. Indian Forum said:

    I think some of these hacks are not required. They can be done straight from the settings panel. One hack which I know can be done from settings is hack # 2. It can be done from the permalink structure settings from inside wp-admin.

  30. Niazi said:

    I want to add my own ModRewrite Rule in wordpress blog. Then what should i do ??

    You can also answer me on niazi587 at gmail dot come

  31. Spunky Jones Blog Tips said:

    I just tried the remove /category/ from the URL.
    RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L] on my blog.
    It works, but when you get to any categories, it won’t let me access pages, like /page/2/ without getting a 404 error.

    It appears that I need something to handle the pages.Any suggestion how to handle the following, /page/*/

  32. Web Talk said:

    i already know all this tips. Just beaware of tip number 8 . In fact, you might get penalized by Google. I also think there could be some issue when Google Images try to display your blog pitures in its results…

  33. Emal said:

    Finally a clear article about htaccess tips !

    2 questions though : is there an easy way to set up a password at the homepage (and the whole blog) ?

    My default htaccess is like this :

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Where should I insert the code you provide ? Anywhere between the two “#” tags?

  34. Firany said:

    Yeah blocking bots is a great way to save a lot of time on comment moderation. Plus you know you won’t miss out on anything important since there hasn’t been one instance in the history that the bot would make a wirthwile comment.

  35. John Hoff - WpBlogHost said:

    You can put it above as the very first item (above the first #) or below the last #, either way will work.

    All the # are, are comments.

    If you’re not familiar with .htaccess, then the easiest way to password protect either a directory or your entire site (i.e. password protect your root) is to set up password protection through your web hosting control panel. Log into your control panel and look for an icon or something name “Password Protect”.

  36. Real Estate Video said:

    These are definitely some great .htaccess tricks. I have actually used a few of these myself. Another resource that I thoroughly enjoy when it comes to .htaccess tricks is at http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/. You can find a ton of different .htaccess stuff there, from optimization to security.

  37. morris bryant said:

    awesome tips, thanks a lot.

    you can do the same thing with categories in the permalink sections by using “/.” but it does throw out ome issues with pagination (does the htaccess change work with pagination?)

    protecting from hotlinking images is really great.

    great post!

  38. Web Design Jaipur said:

    i already know all this tips. Just beaware of tip number 8 . In fact, you might get penalized by Google. I also think there could be some issue when Google Images try to display your blog pitures in its result

  39. Fast food statistics said:

    Just like the user before me mentioned, there’s no such a thing as hacking into your email account using nothing more than your email address. Unless it’s an inside job. Whatever you are using for blog.

  40. tkmk said:

    #7 sorted me out! I was using a dodgy plugin that was doing some crazy stuff to my website and yet adding a maintenance page is soooo easy!


  41. Funny SMS said:

    Previously I was using a plugin called “Top Level Cats” to remove “category” from url. When I tried to upgrade WP to the latest version, that plugin started giving problem.

    Thanks to your tip, I have now upgraded to WP 2.7.1 and everything is working perfect. Thank you so much. :)

  42. ody said:

    Hi!, I can´t upload the .htaccess file…
    553 Can’t open that file: Permission denied
    Error: Critical Error

  43. gas card said:

    The tip #8 is is awesome, but I am wondering about the following… besides having ftp access to the server, I only have the Google Analytics stats, I am wondering.. how do you find out without blocking them first, who is using your images, and content? I would much rather see who is using it, as opposed to blocking them first, hehe.


  44. links for 2009-07-03 « williamlong’s blog said:

    [...] 10 awesome .htaccess hacks for WordPress htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things. In this article, let’s see how .htaccess can help you with your WordPress blog, for both security,functionnality and usability. (tags: wordpress tips) [...]

  45. links for 2009-07-03 | said:

    [...] 10 awesome .htaccess hacks for WordPress .htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things. In this article, let’s see how .htaccess can help you with your WordPress blog, for both security,functionnality and usability. (tags: blog web tools webdesign wordpress blogging tutorial tips resource security howto hack examples mod_rewrite resources hacks webdev articles code wp .htaccess htaccess tutorials development php worpress webserver apache wordpress-hacks access) [...]

  46. Albatol Network said:

    Thanks for the great tips/tricks in htaccess that we all need it.
    only facing one problem after using couple steps in here.
    all my urls ending with (.htm) is there is any htaccess rule/tip to remove that and just get clean url?
    thanks again

  47. avinash said:

    i need your help i am new to wordpress my questions are

    1. is it possible to publish the posts in different directories like if i post it shows
    “www.example.com/your-post” i want to publish the post like “www.example.com/computers/your-post”
    and “www.example.com/internet/your-post”

    2. i install wordpress and i change the permalink settings from “default” to “month and name” and after saving it says “You should update your .htaccess now” but i don’t know where it is and what to update in it.

    i have publish no any posts

    Please help

  48. 润物细无声 » WordPress .htaccess çš„10个Hack技巧 said:

    [...] 注意:以下文章翻译来自英文网站:10 awesome .htaccess hacks for WordPress .htaccess文件是用来控制Apache服务器的,它很有用,并允许你做很多事,下面就介绍关于.htaccess的10个修改方法,让你的wordpress更加的安全、多功能、和可用性! 警告:在修改之前请你备份.htaccess,一边修改后出现错误你可以恢复! 1.重定向你的WordPress RSS feeds 到feedburner或feedsky # temp redirect wordpress content feeds to feedburner <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://在feedburner你的地址 [R=302,NC,L] </IfModule> [...]

  49. Tubagus Rusmawan said:


    i am new to wp. if i want to use all the .htaccess hacks, can anyone show me how to write all the .htaccess hacks in just one .htaccess file?

  50. 卧雪眠云 » 10个WordPressçš„.htaccess技巧 said:

    [...]   对于Apache服务器,使用.htaccess文件可以进行很多相关网络服务访问的配置。而以下的10个技巧则专门针对WordPress所进行的设置,推荐大家参考使用:   参考原文:10 awesome .htaccess hacks for WordPress [...]

  51. John Hoff - WP Blog Host said:

    @ sikiÅŸ – The easiest way to do that if you’re not familiar with .htaccess rules is to simply set up a password protection system through your web hosting control panel.

    Most all hosting companies provide this service. Just a few clicks and you can password protect any directory, including your root.

  52. RWH said:

    Hey Jean, good list of hacks all put together in a nice and easy way. I wasn’t aware that you could utilize .htaccess file so effectively.

  53. WordPress News for 3/31/09 | Projektet II – tankar om ehandel, ledarskap och affärer said:

    [...] Jean-Baptiste tells us about 10 awesome .htaccess hacks for your WordPress blog including the ability to redirect visitors to a maintenance page while you can continue to see and work on your blog. Liknande inlägg:Wordpress i facebook och facebook till wordpressAll In One SEO Lives OnIntressant hemsida om klimatmärkningComment License Made EasyWordPress Plugin Releases for 11/13 Tipsa andra [...]

  54. b00m said:

    Hi there Jean,

    What if I want to change this:

    …link rel=”stylesheet” href=”http://mydomain.com/wp-content/themes/xmnt/style.css” type=…


    …link rel=”stylesheet” href=”/xmnt/style.css” type=…

    I want to hide the root address…Can .htaccess execute like that?
    If can, can You give me some example how to do it. tnx

  55. 搜集岛 » 十个WordPressçš„.htaccess技巧 said:

    [...] 对于Apache服务器,使用.htaccess文件可以进行很多相关网络服务访问的配置。而以下的10个技巧则专门针对WordPress所进行的设置,推荐大家参考使用: 参考原文:10 awesome .htaccess hacks for WordPress [...]

  56. Andrew said:

    Hi Jean,

    I am having problem with WP blog, after upgrade to IE8

    The posts/pages can only opened if the permalinks are set in default.
    Others, will show “The webpage cannot be found” HTTP404

    How to solve? Please

  57. Mike said:

    Good day,

    I’m new to WordPress and I’m trying to add permalinks so my posts are searchable. Problem – I can’t find .htaccess to open and edit it as per wp-admin instructions. If I try and create a new file .htaccess it tells me it is already there. Is it hidden? It’s probably simple but something is escaping me!!! HELP!

  58. 3 simple but awesome .htaccess hacks for your Wordpress blog | w3devil said:

    [...] Source:Cats who code Submit this to Script & StyleDigg this!Stumble upon something good? Share it on StumbleUponShare this on del.icio.usTweet This!Share this on FacebookShare this on TechnoratiShare this on MixxEmail this to a friend?Buzz up!Share this on RedditPost this to MySpaceAdd this to Google BookmarksSubmit this to TwittleyMoo this on DesignMoo!Submit this to NetvibesShare this on Blogosphere NewsRelated Posts :Two awesome Farmville (Facebook) cheats! [...]

  59. web20typ_ – Meine Bookmarks vom November 22nd von 16:08 bis 17:59 said:

    [...] 10 awesome .htaccess hacks for WordPress – .htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things. In this article, lets see how .htaccess can help you with your WordPress blog, for both security,functionnality and usability. – wordpress htaccess tips blog tutorial « Meine Bookmarks vom November 21st bis November 22nd [...]

  60. Alex said:

    Hello, thanks for the post, I have a question.

    When I insert this code to zen-cart .htaccess:

    redirect 301 /odd.html http://www.odddomain.com/new.html

    it did redirect to the new.html, but zencart add certain parameters to the end of the new url which resulted in the show up of the odd.html content while the url is new.html.

    Please help, thanks.

  61. GadgetBoyo said:

    The better way to protect your wp-admin folder with this code

    Order Allow,Deny
    Deny from all

    Allow from all

    allow from xx.xx.xx.xx

    This way when users login they do just see a plain jain ugly page and they get the css loog of the wordpress login.

  62. WordPressçš„.htaccess设置 » 石头 said:

    [...] 对于Apache服务器,使用.htaccess文件可以进行很多相关网络服务访问的配置。而以下的10个技巧则专门针对WordPress所进行的设置,推荐大家参考使用: 参考原文:10 awesome .htaccess hacks for WordPress [...]

  63. 10个WordPress的.htaccess技巧-建站指南-站长经验 » By admin » 发布 » sin32 said:

    [...] 对于Apache服务器,使用.htaccess文件可以进行很多相关网络服务访问的配置。而以下的10个技巧则专门针对WordPress所进行的设置,推荐大家参考使用: 参考原文:10 awesome .htaccess hacks for WordPress译文出自:http://e-spacy.com/blog/10-htaccess-hacks-for-wordpress.html [...]

  64. Robert said:

    In Hack 9 it’s not deny,allow it’s allow,deny. If incomming doesn’t match the deny nor allow condition set then the second is followed as allow all if you have deny,allow and deny all if you have allow,deny.

  65. Shannon - SKS Designs said:

    I am currently using the following permalink structure and am looking to change it through a 301 redirect but cannot find the code that works.

    Currently permalink: /%year%/%monthnum%/%postname%.html
    Future permalink: /%postname%

    Can someone help me?

  66. santosamaru said:

    thanks verry much bro for this information, but i need an regex for the baning ip for spammer that like

    if visitor come without reff then go ban it
    if user agent come then ban go ban it
    but if visitor or user agent comes withboth of two list ( the reff and/real user agents name )its must 200

    sorry im still newb ^^ i want to learn please let me know how to to this
    but if i got thats way i will tell you too


  67. ken said:

    Wow impressive article!
    Recently, I’ve created a new subdomain (the domain has a wordpress blog on it) and I’ve uploaded some avi files there. I’ve created then an html file with links pointing to these movies.

    The problem is I cannot access these files when I click on the links. Is giving me that message with “Nothing found for …”.

    I guess is related to .htaccess file or / and somehow to wordpress since I did the same thing on another domain with no worpdress on it and it works. Any ideas why this problem?

  68. retro said:

    I have a question, I installed my blog in its own directory but followed WordPress instructions to move the index so the blog can be accessed from the main index instead of going to the folder, is there a way to redirect people who try to access my installation folder to the index using .htaccess?

  69. Chris said:

    Very cool stuff. I really like the .htacess that reduces my spam. For the longest time I wondered why I would get a flood of like 20 spam comments however that article had little to no hits.

  70. Patricia said:

    When using a windows server, in this case I have a web.config file, which replaces in that case my htaccess file. How can I incorporate this line to not show the category in the url?
    RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

    I tried this but it does not work:

    Any help would be highly apreciated.


  71. Valex said:


    I need some help with my permalinks – actually I’ve decided to change them from /%category%/%postname%/ to /%year%/%monthnum%/%category%/%postname%/

    Could you please tell me how to 301 redirect them.

    Thanks in advance!

  72. Mark said:

    Having always found .htaccess files a bit of a black art (but more obscure), this post contains some really great tips that I will be trying out soon.

    I especially like the ones to do with blocking spammers, as some of our blogs get a ton of comment spam (which Akismet picks up, for the most part, fortunately).

    I also love the idea of replacing hot-linked banners with adverts for your own site. Brilliant!

  73. khaleed said:

    This is great tips. Thank you for sharing with us. Especially point no 5, it’s really help me with permalink.

    Just want to share that if anybody experiencing a problem with “404 error not found” in google webmaster tool, right now there is a plugin that can fix it. Just search in the plugin area and you will have a lot of plugin regarding redirecting no need to modified your ht.access anymore.


  74. sara said:

    not sure why when i use #7 it displays a blank page. I have an image on there with some links to other social sites but none of this displays when using the #7 hack.

    Help please?

  75. Jimmy said:

    Redirect Day and name permalinks to /%postname%/
    Your code is the only one that has worked for me from the other methods I’ve been trying in the past hour. Thanks heaps!

  76. Stephen said:

    Just belatedly came across this article – some great htaccess tips here and I’ve just implemented them on a WordPress site. Thanks Jean-Baptiste! :)

  77. Doug Asker said:

    I am not all that familiar with WordPress. So if I want to use all the .htaccess hacks, can anyone show me how to write all the .htaccess hacks in just one .htaccess file?

  78. Stephen Sanders said:

    To the comment above, don’t think you block all spammers and hackers, on some level it cannot (and should not) be attempted: You might find a better explanation as to why on:

  79. jay hands said:

    I was looking for a way to redirect web visitors to a ‘maintenance page’ while I was doing some update work and I found this post. I am not a coder but popped in your code and it worked. Thanks a lot for taking the time to share your information – by the looks of it you have helped a few people out! Thanks Jay.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!