脚本宝典收集整理的这篇文章主要介绍了如何在PHP中重写URL?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。@H_126_0@ 我正在尝试在我的 PHP应用程序中实现URL重写.有人可以分享PHP和MysqL中实现URL重写的一步一步的过程吗?
在我的应用程序中,我想实现以下URL重写,我想重定向
1. http://example.COM/videos/play/GOOGLE-io-2009-wave-intro 2. http://example.com/videos/play/203/google-io-2009-wave-intro
至
1. http://example.com/videos/play.PHP?tITle=google-io-2009-wave-intro 2. http://example.com/videos/play.PHP?id=203
请告诉我如何以上述方式实现URL重写.
根据SEO,管理,应用程序的观点,以下两种类型的URL最好还是一个.
1. http://example.com/videos/play/google-io-2009-wave-intro 2. http://example.com/videos/play/203/google-io-2009-wave-intro
通常,这将不仅仅是启用Mod_rewrite模块(您可能已经为主机启用),然后将.htaccess文件添加到您的web目录中.一旦你这样做,你只有几条线远离完成.上面链接的教程将会照顾你.
只是为了好玩,这是一个Kohana .htaccess文件重写:
# Turn on URL rewriting RewriteEngine On # Installation directory RewriteBase /rootDir/ # PRotect application and system files From being viewed rewriterule ^(application|modules|system) - [F,L] # Allow any files or directories that exist to be displayed directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Rewrite all other URLs to index.PHP/ RewriteRule .* index.PHP/$0 [PT,L]
这将是所有请求,并通过index.PHP文件通过它们.所以如果您访问过www.examplesite.com/subjects/PHP,您可能会访问www.examplesite.com/index.PHP?a=subjects\u0026amp;b=PHP.
如果您发现这些URL有吸引力,我会鼓励您进一步了解MVC框架(模型,视图,控制器).它本质上允许您像一组功能对待您的网站:
www.mysite.com/jokes
public function jokes ($page = 1) { # Show Joke Page (defaults to page 1) }
或者,www.mysite.com/jokes/2
public function jokes ($page = 1) { # Show Page 2 of Jokes (Page 2 because of our different URL) }
以上是脚本宝典为你收集整理的如何在PHP中重写URL?全部内容,希望文章能够帮你解决如何在PHP中重写URL?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。