我想在我的。htaccess文件中使用mod_rewrite重写Word Press url,方法如下:
http://blog.com/content/themes/twentyeleven/style.css
http://blog.com/wp-content/themes/twentyeleven/style.css
和
http://blog.com/inc/css/admin-bar.css?ver=20110622
http://blog.com/wp-includes/css/admin-bar.css?ver=20110622
和
http://blog.com/admin/post.php?post=1&action=edit
http://blog.com/wp-admin/post.php?post=1&action=edit
我试图隐藏这个事实,这个网站是使用Word Press,和所有的链接已经用PHP重写的飞行。然而,我希望服务器重写链接回到正确的Word Press的上面。
如果它有帮助,我已经准备了一个文件(在我的php.ini文件)到Wordpress index.php文件调用ob_start();函数,然后附加以下文件:
<?php
$html = ob_get_contents();
ob_end_clean();
$html = str_replace("wp-content", "content", $html);
$html = str_replace("wp-admin", "admin", $html);
$html = str_replace("wp-includes", "inc", $html);
echo $html;
?>
有些人可能会问我为什么要隐藏我们正在使用Word Press的事实。有很多原因(安全是其中之一),但这并不是这个问题的真正重点。
我可以添加什么代码到我的。htaccess文件,让我重写url,但保持正确的查询字符串,如?ver=20110622或?post=1&action=edit
在重写URL时,[QSA]
标志将保留查询字符串。例子:
RewriteRule ^content/(.*?) wp-content/$1 [QSA]