我在 .htaccess 上遇到了困难。我想为我正在开发的网站创建友好的 URL...
基本上我想转换这个:
http://website.com/index.php?ctrl=pelicula&id=0221889
http://website.com/index.php?ctrl=pelicula&id=0160399&tab=posters
进入这个:
http://website.com/pelicula/0221889/
http://website.com/pelicula/0221889/posters/
如果以后需要的话,我还想知道如何将文章标题添加到 URL 的末尾,如下所示(我使用的是 PHP):
http://website.com/pelicula/0221889/the-article-name/
http://website.com/pelicula/0221889/the-article-name/posters/
注意:Stackoverflow方法对我来说也很好,例如这个问题的url是:
http://stackoverflow.com/questions/3033407/htacces-to-create-friendly-urls-help-needed
但是你可以在 id 之后添加任何内容,它也会起作用。像这样:
http://stackoverflow.com/questions/3033407/just-anything-i-want
我使用了一些自动 Web 工具来创建 .htaccess 文件,但它无法正常工作。所以我请求你的帮助。
如果您能推荐 .htaccess 最佳实践和建议,我也将很高兴。
编辑:根据我在这里得到的一些答案,我这样写:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]+)/([^/]+)/?([^/]*)/?$ index.php?ctrl=$1&id=$2&tab=$3 [QSA,L]
</IfModule>
但我收到默认主机“找不到页面”错误。
我也尝试过:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(\d+)/([^/]+)/?$ index.php?ctrl=$1&id=$2&tab=$3 [QSA,L]
RewriteRule ^([^/]+)/(\d+)/?$ index.php?ctrl=$1&id=$2 [QSA,L]
RewriteRule ^([^/]+)/?$ index.php?ctrl=$1 [QSA,L]
</IfModule>
这也是行不通的。它带我到我的默认 404.php 页面。
mod_rewrite 已启用并正在工作。
Help!