我怎样才能mod_rewrite的,并保持查询字符串?(How can I mod_rewrite and keep query strings)

   IT问题网   2018-11-15 00:00:00

问 题

我要mod_rewrite的一个url到另一个页面,后来我也想添加任何查询字符串是preserved。

rewriteengine叙述上

#enforce尾随斜线
的rewritecond%{} request_filename!-f
的rewritecond%{request_uri}!#
的rewritecond%{request_uri}!(。*)/ $
重写规则^ $ http(*)://本地主机/ siteroot / $ 1 / [l,r = 301]

重写规则^应用程序/([a-za-z0-9 -_] +)/ $的index.php和放大器;应用程序= $ 1
 

因此,如果用户访问应用程序/ app1 / ,的index.php?应用= app1 显示。 不过,我希望能够以preserve可选的查询字符串,使来访应用程序/ app1 /?变量= x 返回的index.php ?应用程序= app1和放大器;变量= x

什么的mod_rewrite规则/条件会做到这一点?

解决方案

您需要添加的[qsa] 标志("查询字符串附加")

 重写规则^应用程序/([a-za-z0-9 -_] +)/ $的index.php和放大器;应用程序= $ 1 [l,qsa]
 

有关301页面重定向与 [r] 标记,而不是内部重写像这样的,查询字符串将自动添加。但是,你必须强迫它 [qsa] 的内部重写。

标签:怎样才能保持维持查询字符串



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何从PHP脚本改变外观的URL(How to change appearance of URL from within a PHP script)

problem i have some php and html in the same file, and i ...

删除尾随的问号htaccess的(Removing trailing question mark with htaccess)

problem can someone help me understand this code # remov ...

URL重写GET参数(URL Rewrite GET parameters)

problem i want my url to look like the following www.web ...

htaccess的从XAMPP转向灯开的Ubuntu 13.10后不工作(启用htaccess的Apache中的Linux服务器)(htaccess is not working after moving from XAMPP to LAMP on ubuntu 13.10 (Enable htaccess in apache linux server))

problem my codeigniter project is running successfullyon ...

查询字符串和放大器;国防部重写(Query Strings & Mod ReWrite)

problem i'm not too inexperienced with rewrite (not a mas ...

在.xml文件PHP的错误?(PHP error in .xml file)

problem ok firstly, i added this line to my .htaccess fil ...

使用Apache的mod_rewrite解析搜索引擎友好的URL(using apache's mod_rewrite to parse SEO friendly URL's)

problem how do i convert something like me.com/profile/2 ...

搜索引擎友好的URL(Search-Engine Friendly URLs)

problem i am working on building my first search-engine f ...

斜杠之后将文字与.htaccess的变量(Turn text after slashes into variables with HTACCESS)

problem i need to pass 3 variables with a url but using s ...

从URL删除字符与htaccess的(Remove Characters from URL with htaccess)

problem hopefully someone can see what i'm do ...

重定向所有的HTML扩展到.PHP(redirect all .html extensions to .php)

problem i want to update all the pages on a website to us ...

需要转义#(哈希/磅)字符在.htaccess重写规则(need to escape # (hash/pound) character in .htaccess rewrite rule)

problem the question is fairly simple but i w ...

如何使用的.htaccess重写规则改变下划线以破折号(How do I use .htaccess RewriteRule to change underscores to dashes)

problem i'm working on a site, and its cms used to save n ...

请求实体太大PHP(Request Entity Too Large PHP)

problem in one of my cakephp site, i got this error. req ...

的.htaccess使用PHP $ _GET缩短网址(.htaccess shorten URL using php $_GET)

problem i need to be able to shorten my page from: mydom ...

Gzip已融为一体pression通过的.htaccess不工作(Gzip compression through .htaccess not working)

problem i have been creating a site and checking it's spe ...

重定向www.subdomain.example.com到subdomain.example.com(redirecting www.subdomain.example.com to subdomain.example.com)

problem i've had some users trying to access a site that ...

添加尾随斜线的.htaccess(Add Trailing Slash .htaccess)

problem i'm trying to get the following effec ...

禁用所有的CGI(PHP,PERL,...)使用的.htaccess目录(Disable all CGI (php, perl, …) for a directory using .htaccess)

problem i have a directory where users can upload files. ...

在某个目录设置为仅附件上的文件内容处理标头?(Set Content-Disposition header to attachment only on files in a certain directory)

problem i've got this this rule in my htaccess file to fo ...