我正在尝试在我的
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
A Beginner’s Guide to mod_rewrite.
原文链接:https://www.f2er.com/php/138104.html通常,这将不仅仅是启用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) }