如何在不指定参数的情况下处理URL
我想知道是否可以在不指定参数的情况下处理 URL。例如: http://www.example.com/Sometext_I_want_to_process
我不想使用:http://www.example.com/index.php?text=Sometext_I_want_to_process
该网站在处理后必须重定向到不同的页面。
我有什么语言选择?
I was wondering if I could process an URL without specifing parameters. For example:http://www.example.com/Sometext_I_want_to_process
I don't want to use: http://www.example.com/index.php?text=Sometext_I_want_to_process
The site has to redirect to a different page after processing.
What language choice do I have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 apache 的 mod_rewrite (在其他网络服务器上也有类似的功能)来重写 URL,使其成为一个参数。例如,对于您使用的文本参数,您可以使用以下 mod_rewrite 规则来获取参数。
然后,您只需像平常一样访问脚本中的参数即可。
I would suggest using apache's mod_rewrite (similar functionality is found on other webservers) to rewrite the URL so that it is a parameter. For instance with the text parameter you use, you could use the following mod_rewrite rules to get the parameter.
Then you simply access the parameter in the script like you normally would.
您可以使用 Apache 的
mod_rewrite
< /a>.显然,这意味着必须启用它 - 默认情况下通常不是这种情况。
例如,在网站上,我在
.htaccess
文件:这会重定向所有内容,例如
www.mysite .com/152
到www.mysite.com/index.php?hash=152
然后,在我的 PHP 代码中,我可以使用
$_GET
> :就您而言,您可能希望将“
hash
”替换为“text
”,但这应该已经帮助您更接近解决方案了;-)You can do that kind of thing using Apache's
mod_rewrite
.Obvisouly, it means it must be enabled -- which is too often not the case by default.
For instance, on a website, I use this in a
.htaccess
file :This redirects everything, like
www.mysite.com/152
towww.mysite.com/index.php?hash=152
And, then, in my PHP code, I can just use
$_GET
:In your case, you'll probably want to replace "
hash
" by "text
", but this should already help you getting closer to the solution ;-)