PHP mod rewrite .htaccess文件godaddy.com问题

4
我对PHP不是很熟悉,最近我想学习使用mod rewrite来重写我的URL。我使用的是godaddy公司提供的托管服务,并且他们说要将所需的代码添加到.htaccess文件的主体中。请问如何mod rewrite我的URL并将其添加到我的.htaccess文件中?
有人能给我一个示例代码吗?同时,还可以向我推荐一些好的教程或书籍来学习如何mod rewrite我的URLs吗?
1个回答

3

http://articles.sitepoint.com/article/guide-url-rewriting

需要注意的是,goDaddy通常需要RewriteBase /

快速而简单。

RewriteEngine On
RewriteBase /
RewriteRule ^/?about/?$ about.php [L,NC,QSA] # domain.com/about is sent to the server as domain.com/about.php
RewriteRule ^/products/([0-9]+)$ /products.php?id=$1 [L,NC,QSA]  # domain.com/products/23 is sent to the server as domain.com/products.php?id=23 

我需要为每个文件夹和子文件夹都这样做吗? - max
只有当您需要针对它们的特定规则时才会使用它们,例如文件夹/secretArea可能会有自己的htaccess文件用于某些目的。通常,您会在站点的根目录中找到它们。 - Dan Heberden
你对GoDaddy需要RewriteBase /的评论让我省了很多麻烦。 - Manatax

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接