Rewrite directories using mod_rewrite but keeping query strings
I'm wanting to rewrite Word Press urls using mod_rewrite in my .htaccess file in the following ways:
http://blog.com/content/themes/twentyeleven/style.css
to
http://blog.com/wp-content/themes/twentyeleven/style.css
and
http://blog.com/inc/css/admin-bar.css?ver=20110622
to
http://blog.com/wp-includes/css/admin-bar.css?ver=20110622
and
http://blog.com/admin/post.php?post=1&action=edit
to
http://blog.com/wp-admin/post.php?post=1&action=edit
I'm trying to hide the fact that this website is using Word Press, and all links have been rewritten on the fly using PHP. However I want the server to rewrite the links back to the correct Word Press ones as above.
In case it helps, I've prepended a file (in my php.ini file) to the Wordpress index.php file which calls the ob_start(); function and then appended the following file:
<?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;
?>
Some people may question why I want to hide the fact that we're using Word Press. There are many reasons (security being one of them) but that's not really the point to this question.
What co开发者_如何学JAVAde can I add to my .htaccess file that would let me rewrite the urls but keeping the correct query strings such as ?ver=20110622 or ?post=1&action=edit
The [QSA]
flag will maintain the query string when rewriting the URL. Example:
RewriteRule ^content/(.*?) wp-content/$1 [QSA]
精彩评论