简体   繁体   English

URL重写短语问题

[英]URL rewrite phrase issues

I have a URL that I wish to rewrite mysite.com/accounts?id=test should be directed to mysite.com/accounts.php?id=test . 我有一个URL,希望将其重写mysite.com/accounts?id=test定向到mysite.com/accounts.php?id=test I've checked my mod_rewrite , it works, as other pages can be written correctly. 我已经检查了mod_rewrite ,它可以正常工作,因为其他页面可以正确写入。 I am currently trying this: 我目前正在尝试:

RewriteRule ^accounts?([.]+)$ accounts.php?$1 [NC,L]

This does not seem to work. 这似乎不起作用。 Is it because of the question mark in the regular expression? 是否因为正则表达式中的问号? I tried escaping it with \\ but it still does not work. 我尝试使用\\进行转义,但仍然无法正常工作。

Any help would be appreciated. 任何帮助,将不胜感激。

First i thought the ([.]+) is the same as (.*) . 首先,我认为([.]+)(.*)相同。

Second, RewriteRule already strips your query_string from the URL. 其次,RewriteRule已经从URL中剥离了query_string。
You can access it with %{QUERY_STRING} . 您可以使用%{QUERY_STRING}进行访问。

So your code would be 所以你的代码是

RewriteRule ^accounts?(.*)$ accounts.php?%{QUERY_STRING} [NC,L]

You can create an accounts.php with the following to test: 您可以使用以下内容创建一个accounts.php进行测试:

<?php
echo "<pre>";
print_r($_SERVER);
exit();
// rest of your code
?>

and then check your [QUERY_STRING] . 然后检查您的[QUERY_STRING]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM