使用mod_rewrite但保留查询字符串重写目录 [英] Rewrite directories using mod_rewrite but keeping query strings
问题描述
我想重写使用mod_rewrite字preSS的网址在我的.htaccess文件在以下几个方面:
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
到
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的所有链接都被改写的飞行。不过,我希望服务器重写链接回到正确的单词preSS那些如上。
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.
在情况下,它可以帮助,我已经prepended一个文件(在我的php.ini文件),该函数调用ob_start道preSS index.php文件();函数,然后附加以下文件:
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;
?>
也许有人会质疑我为什么要隐瞒,我们正在使用Word preSS的事实。原因是多方面的(安全性是其中之一),但是这不是真的点到这个问题。
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.
我可以添加到我的.htaccess文件什么code,将让我重写的URL,但保持正确的查询字符串,如版本= 20110622或交= 1&安培;?行动=编辑
What code 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
推荐答案
URL重写时, [QSA]
标志将维护查询字符串。例如:
The [QSA]
flag will maintain the query string when rewriting the URL. Example:
RewriteRule ^content/(.*?) wp-content/$1 [QSA]
这篇关于使用mod_rewrite但保留查询字符串重写目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!