问题描述
这我的应用程序使用的实际网址是:
The actually URL which my app uses is:
http://site.com/search.php?search=iPhone
但我想它是可能的,以达到同样的
but I would like it to be possible to achieve the same with
http://site.com/iPhone
我有重写规则没有经验,我该如何设置呢?
I have no experience of rewrite rules, how can I set this up?
该解决方案的工作,但新的URL显示在地址栏。我认为这将是可能的,这样看起来好像页面位置设置此
The solution has worked but the new URL is displayed in the address bar. I thought it would have been possible to set this up so that it appears as though the page location is
http://site.com/iPhone
在不改变显示
http://site.com/search.php?search=iPhone
这可能吗?谢谢你。
Is this possible? Thanks.
推荐答案
在您的网站的根目录下创建一个名为.htaccess文件,并把这个在里面。
Create a file called .htaccess in the root of your website and put this in it.
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*) search.php?search=$1 [R]
应该做的伎俩。
Should do the trick.
不过,我建议你把它多一点具体的,也许需要一个搜索目录中您的网址的用户。例如,而不是mysite.com/IPhone使用mysite.com/search/IPhone这将工作像
I would suggest however that you make it a bit more specific, so maybe require the user of a search directory in your url. eg instead of mysite.com/IPhone use mysite.com/search/IPhone which would work like
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^search/(.*) search.php?search=$1 [R]
这使得它更容易有正常的网页,ARNT重定向,如关于我们或者一个基本的网页。
This makes it easier to have normal pages that arnt redirected, such as about us or a basic homepage.
由于克里斯说,这不是PHP,但Apache的,这是否,以及是否它的工作原理可能取决于你的主机设置。
As Chris says, this is not PHP but Apache that does this, and whether it works can depend on your hosting setup.
这篇关于PHP重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!