<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>WordPress使用教程与分享 &#187; .htaccess</title> <atom:link href="http://kisswp.com/tag/htaccess/feed" rel="self" type="application/rss+xml" /><link>http://kisswp.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Wed, 21 Jul 2010 04:02:54 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>在WordPress的10个.htaccess技巧</title><link>http://kisswp.com/2009/09/12/36.html</link> <comments>http://kisswp.com/2009/09/12/36.html#comments</comments> <pubDate>Sat, 12 Sep 2009 06:52:23 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[.htaccess]]></category><guid isPermaLink="false">http://kisswp.com/?p=36</guid> <description><![CDATA[1. 重定向WordPress的订阅地址 除了修改WordPress的模板文件来定制其输出的RSS Feed链接地址外，还可以使用.htaccess文件来进行设置(替换yourrssfeedlink为自己的Feedburner地址)。 # temp redirect wordpress content feeds to feedburner &#60;IfModule mod_rewrite.c&#62; 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] &#60;/IfModule&#62; 参考：How to redirect WordPress rss feeds to feedburner 2. 去除WordPress分类链接中的“/category/”前缀 默认情况下，WordPress的分类链接显示的样式为： http://xxx.com/blog/category/tech 其实其中的category部分没有任何意义，如果想去掉它可以修改.htaccess文件(替换yourblog为自己的网址)。 RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L] 参考：How to remove category from your WordPress url 3. [...]]]></description> <content:encoded><![CDATA[<h5>1. 重定向WordPress的订阅地址</h5><p>除了修改WordPress的模板文件来定制其输出的RSS Feed链接地址外，还可以使用.htaccess文件来进行设置(替换yourrssfeedlink为自己的Feedburner地址)。<br /> <code># temp redirect wordpress content feeds to feedburner<br /> &lt;IfModule mod_rewrite.c&gt;<br /> RewriteEngine on<br /> RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]<br /> RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]<br /> RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.feedburner.com/catswhocode [R=302,NC,L]<br /> &lt;/IfModule&gt;</code><br /> 参考：<a href="http://www.wprecipes.com/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-htaccess">How to redirect WordPress rss feeds to feedburner</a><span id="more-36"></span></p><h5>2. 去除WordPress分类链接中的“/category/”前缀</h5><p>默认情况下，WordPress的分类链接显示的样式为：<br /> <code>http://xxx.com/blog/category/tech</code><br /> 其实其中的category部分没有任何意义，如果想去掉它可以修改.htaccess文件(替换yourblog为自己的网址)。<br /> <code>RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]</code><br /> 参考：<a href="http://www.wprecipes.com/how-to-remove-category-from-your-wordpress-url">How to remove category from your WordPress url</a></p><h5>3. 使用浏览器缓存</h5><p>可以修改.htaccess文件让访问者使用浏览器缓存来优化其访问速度。<br /> <code>FileETag MTime Size<br /> &lt;ifmodule mod_expires.c&gt;<br /> &lt;filesmatch ".(jpg|gif|png|css|js)$"&gt;<br /> ExpiresActive on<br /> ExpiresDefault "access plus 1 year"<br /> &lt;/filesmatch&gt;<br /> &lt;/ifmodule&gt;</code><br /> 参考： <a href="http://www.wordpress-tutoriel.com/tutoriel/comment-accelerer-le-temps-de-chargement-de-votre-blog/">Comment accelerer le temps de chargement de votre blog</a></p><h5>4. 压缩静态数据</h5><p>可以修改.htaccess文件来压缩需要访问的数据（传输后在访问端解压），从而可以减少访问流量和载入时间。<br /> <code>AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript<br /> BrowserMatch ^Mozilla/4 gzip-only-text/html<br /> BrowserMatch ^Mozilla/4.0[678] no-gzip<br /> BrowserMatch bMSIE !no-gzip !gzip-only-text/html</code></p><h5>5. 重定向日期格式的WP Permalink链接地址为Postname格式</h5><p>如果你目 前的Permalink地址为/%year%/%monthnum%/%day%/%postname%/ 的格式，那么我强烈推荐你直接使用/%postname%/ ，这样对搜索引擎要舒服得多。首先你需要在WordPress的后台设置输出的Permalinks格式为/%postname%/ 。然后修改.htaccess文件来重定向旧的链接，不然别人以前收藏你的网址都会转成404哦！(替换yourdomain为自己的网址)<br /> <code>RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.yourdomain.com/$4</code><br /> 参考： <a href="http://www.wprecipes.com/redirect-day-and-name-permalinks-to-postname">Redirect day and name permalinks to postname</a></p><h5>6. 阻止没有referrer来源链接的垃圾评论</h5><p>设置.htaccess文件可以阻止大多数无Refferrer来源的垃圾评论机器人Bot Spammer。其会查询访问你网站的来源链接，然后阻止其通过wp-comments-post.php来进行垃圾评论。<br /> <code>RewriteEngine On<br /> RewriteCond %{REQUEST_METHOD} POST<br /> RewriteCond %{REQUEST_URI} .wp-comments-post.php*<br /> RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]<br /> RewriteCond %{HTTP_USER_AGENT} ^$<br /> RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]</code><br /> 参考： <a href="http://www.wprecipes.com/how-to-deny-comment-posting-to-no-referrer-requests">How to deny comment posting to no referrer requests</a></p><h5>7. 定制访问者跳转到维护页面</h5><p>当你进行网站升级，模板修改调试等操作时，最好让访问者临时 跳转到一个声明的维护页面(和404错误页面不同)，来通知网站暂时无法访问，而不是留下一片空白或者什么http bad错误。（替换maintenance.html为自己定制的维护页面网址，替换123.123.123.123为自己目前的IP地址，不然你自己访 问也跳转哦）<br /> <code>RewriteEngine on<br /> RewriteCond %{REQUEST_URI} !/maintenance.html$<br /> RewriteCond %{REMOTE_ADDR} !^123.123.123.123<br /> RewriteRule $ /maintenance.html [R=302,L]</code><br /> 参考：<a href="http://www.woueb.net/2007/07/25/comment-faire-une-page-d-accueil-pour-les-internautes/">Comment faire une page d’accueil pour les internautes</a></p><h5>8. 设置你的WordPress防盗链</h5><p>盗链是指其它网站直接使用你自己网站内的资源，从而浪费网站的流量和带宽，比如图片，上传的音乐，电影等文件。（替换mysite为自己的网址和/images/notlink.jpg为自己定制的防盗链声明图片）<br /> <code>RewriteEngine On<br /> #Replace ?mysite.com/ with your blog url<br /> RewriteCond %{HTTP_REFERER} !^http://(.+.)?mysite.com/ [NC]<br /> RewriteCond %{HTTP_REFERER} !^$<br /> #Replace /images/nohotlink.jpg with your "don't hotlink" image url<br /> RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]</code><br /> 参考：<a href="http://www.wprecipes.com/how-to-protect-your-wordpress-blog-from-hotlinking">How to protect your WordPress blog from hotlinking</a></p><h5>9. 只允许自己的IP访问wp-admin</h5><p>如果你不是团队合作Blog，最好设置只有自己能够访问WP的后台。前提是你的IP不是像我一样动态的哦。（替换xx.xx.xx.xx为自己的IP地址）<br /> <code>AuthUserFile /dev/null<br /> AuthGroupFile /dev/null<br /> AuthName "Example Access Control"<br /> AuthType Basic<br /> &lt;LIMIT GET&gt;<br /> order deny,allow<br /> deny from all<br /> allow from xx.xx.xx.xx<br /> &lt;/LIMIT&gt;</code><br /> 参考：<a href="http://www.reubenyau.com/protecting-the-wordpress-wp-admin-folder/">Protecting the WordPress wp-admin folder</a></p><h5>10. 阻止指定IP的访问</h5><p>如果你想要阻止指定IP的访问，来防止其垃圾评论，那么你可以创建自己的Backlist黑名单。(替换xx.xx.xx.xx为指定的IP地址)<br /> <code>&lt;Limit GET POST&gt;<br /> order allow,deny<br /> deny from xx.xx.xx.xx<br /> allow from all<br /> &lt;/Limit&gt;</code><br /> 参考：<a href="http://lorelle.wordpress.com/2007/09/20/the-easiest-way-to-ban-a-wordpress-spammer/">The easiest way to ban a WordPress spammer</a></p><p>英文原文: <a href="http://www.catswhocode.com/blog/10-awesome-htaccess-hacks-for-wordpress" target="_blank">10 awesome .htaccess hacks for WordPress</a></p><p>中文译文: <a href="http://e-spacy.com/blog/10-htaccess-hacks-for-wordpress.html" target="_blank">10个WordPress的.htaccess技巧</a></p><hr />支持WordPress发展，欢迎向我们<a href="http://kisswp.com/delivery" target="_blank">投稿</a>！ )</small>]]></content:encoded> <wfw:commentRss>http://kisswp.com/2009/09/12/36.html/feed</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>