URL 重写(PHP & Apache 本地服务器)
URL Rewriting (PHP & Apache Local Server)
我正在使用 EasyPHP 14.1 DevServer,目前正在我的计算机上开发自己的网站。
今天有人向我介绍了一种名为 URL Routing/Rewriting 的新方法。
我发现 this 有用的网站生成了我需要添加到我的 httpd.conf 文件中的行。
(我仔细检查过,重写模块是运行)
我试了一个简单的例子,实际上有几个,none 个成功了。
我试图通过将这些行添加到 httpd.conf
来从 http://localhost/47.html to http://localhost/site1/showproducts.php?id=47 重定向自己
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /site1/showproducts.php?id= [L]
我想要这个linkhttp://localhost/site1/products/47/ to lead to http://localhost/site1/showproduct.php?id=47
我对此还很陌生,如有任何帮助,我们将不胜感激
好的,更新一下,
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteRule ^products/([0-9]+)/?$ showproduct.php?id= [NC,L] # Handle product requests
这会起作用。
我正在使用 EasyPHP 14.1 DevServer,目前正在我的计算机上开发自己的网站。 今天有人向我介绍了一种名为 URL Routing/Rewriting 的新方法。 我发现 this 有用的网站生成了我需要添加到我的 httpd.conf 文件中的行。
(我仔细检查过,重写模块是运行)
我试了一个简单的例子,实际上有几个,none 个成功了。
我试图通过将这些行添加到 httpd.conf
来从 http://localhost/47.html to http://localhost/site1/showproducts.php?id=47 重定向自己RewriteEngine On
RewriteRule ^([^/]*)\.html$ /site1/showproducts.php?id= [L]
我想要这个linkhttp://localhost/site1/products/47/ to lead to http://localhost/site1/showproduct.php?id=47
我对此还很陌生,如有任何帮助,我们将不胜感激
好的,更新一下,
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteRule ^products/([0-9]+)/?$ showproduct.php?id= [NC,L] # Handle product requests
这会起作用。