重定向 htaccess 还是 php?
你怎么做到这一点...
当用户输入
http://domain.com/mycompanyname
浏览器重定向到
http://manager.domain.com/page.php?company=mycompanyname
注意:mycompanyname 值是动态的
How do you do this...
When the user enters
http://domain.com/mycompanyname
browser redirects to
http://manager.domain.com/page.php?company=mycompanyname
Note: mycompanyname value is dynamic
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试这个解决方案(从我对 类似问题 的回答复制)
除了使用 mod_rewrite 之外,正如已经报道的那样,您可以通过一个简单的技巧来实现一些魔法。
将像这样的指令放入 .htaccess 中,
用您选择的正则表达式替换 ^servlet$ (它将是您的调度程序的名称)
文件 servlet 应该与此类似
url 可以采用以下形式: http://yoursite/servlet/reports/sales/2009
您还可以访问表单http://yoursite/reports/sales/2009
稍微玩一下 .htacces 和调度程序。
此方法的优点是不需要 mod_rewrite,因为 FilesMatch (1.3+) 和 ForceType (2.0+) 都在 apache 核心中
请参阅参考
http://httpd.apache.org/docs/2.2/mod/ core.html#forcetype
http://httpd.apache.org/docs/2.2/mod/ core.html#filesmatch
http://www.devarticles .com/c/a/Apache/Using-ForceType-For-Nicer-Page-URLs/1/
Try this solution (copied from my answer to similar question )
Other than using mod_rewrite, as already reported you can do a little of magic with a simple trick.
Put into the .htaccess a directive like this one
substitute ^servlet$ with a regular expression of your choice (it will be the name of your dispatcher)
The file servlet should be similar to this
The url can have the form: http://yoursite/servlet/reports/sales/2009
you can also reach the form http://yoursite/reports/sales/2009
plaiyng a little with the .htacces and the dispatcher.
This method has the advantage that mod_rewrite is not required as FilesMatch (1.3+) and ForceType (2.0+) are in the apache core
See for reference
http://httpd.apache.org/docs/2.2/mod/core.html#forcetype
http://httpd.apache.org/docs/2.2/mod/core.html#filesmatch
http://www.devarticles.com/c/a/Apache/Using-ForceType-For-Nicer-Page-URLs/1/
将以下代码放入您的
http://domain.com/mycompanyname
place the following code in your
http://domain.com/mycompanyname
您可以在 php 页面顶部使用它
一旦用户访问您的页面,用户就会被重定向到新的 url
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.facebook.com/people/Wasim-Karani/1158880522" );
在这种情况下,用户将被重定向到 http://www.facebook.com/people/Wasim-Karani/1158880522
You can use this at the top of your php page
As soon as user visits your page, user would be redirected to a new-url
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.facebook.com/people/Wasim-Karani/1158880522" );
In this case user will be redirected to http://www.facebook.com/people/Wasim-Karani/1158880522
我相信 PHP 可以完成这项工作,所以我会告诉你它。首先获取页面的 URL,然后将其拆分以获取 mycompany 并将其保存在变量中。现在让 PHP 加载带有变量的新页面...
这将使用 PHP 来完成...
I believe PHP will do the job, so I will tell you about it. First get the URL of the page then split it to get mycompany and save it in a variable. Now let the PHP loads the new page with the variable ...
this will do it using the PHP ...