如何从网址中删除问号 [英] How to remove question mark from URL

查看:206
本文介绍了如何从网址中删除问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以从网址中删除问号?现在,我们可以说URL可以是 http://www.domain.com/profile?a=10 ,但也可以是 http:/ /www.domain.com/profile?b=ticket

Is there any way I can remove the question mark from URL? Now lets say that the URL can be http://www.domain.com/profile?a=10 but it can also be http://www.domain.com/profile?b=ticket.

因此,在第一种情况下,我的网址应为 http://www.domain.com/profile/10 在第二个 http://www.domain.com/profile/ticket 中。

So in the first case my URL should be http://www.domain.com/profile/10 and in the second http://www.domain.com/profile/ticket.

但是我仍然想要才能在 PHP 中使用 $ _ GET 。因此,我真正想要的是仅向用户删除问号,但是在服务器中,它应该起作用。有什么办法可以执行此操作,可能使用 htaccess 。我在Ubuntu 14.10上将 apache2 作为Web服务器运行。

But I still want to be able to use $_GET in PHP. So what I really want is to remove the question mark only to the user, but in the server it should work the same. Is there any way I can do this, probably using htaccess. I am running apache2 as my webserver on Ubuntu 14.10.

推荐答案

是您可以使用 .htaccess

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^profile/([^.]*)$ profile.php?a=$1&b=$1 [QSA,L]
</IfModule>

其中profile.php是处理这两种情况的PHP代码。

where profile.php will be your PHP code that handles both the cases.

这篇关于如何从网址中删除问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆