我在互联网上寻找了一份全面的.htaccess指南,但没有用,所以我想知道这个网站上的一个用户是否可以帮助我将其配置为我需要做的事情,并给出解释,这样我将来就可以自己解决问题了。
我需要做的是
http://www.url.com/view/{id}
实际上是
http://www.url.com/home.php?p=10&id={id}
如果你能帮忙,我将不胜感激。
将以下内容放在根web目录中的.htaccess文件中,将提供您概述的规范。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# (optional) do not rewrite if the request points to an actual file or directory on disk
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# rewrite the request
RewriteRule ^view/(.*) /home.php?p=10&id=$1 [L]
</IfModule>
这里有很好的参考:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
您应该部署和配置Mod_Rewrite模块以与Apache服务器一起工作。然后,在.htaccess
文件中添加以下行:
RewriteEngine on
RewriteBase /
RewriteRule ^view/(.+) /home.php?p=10&id=$1 [L]