我使用.htaccess看过/读过有关干净网址的问题,但对于我的生活,我无法让他们为我的特定需求而工作。我不断收到404消息。如何仅为2个变量获取干净的URL?
例子:www.mysite.com/article.php?id=1 &标题= MY-博客标题
我想为网址是:www.mysite.com/article/1/my -blog标题
这里是我迄今为止在我的.htaccess:
Options -MultiViews
#DirectorySlash on
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L]
# Rewrite for article.php?id=1&title=Title-Goes-Here
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+) article.php?id=$1&title=$2 [NC,L]
#Rewrite for certain files with .php extension
RewriteRule ^contact$ contact.php
RewriteRule ^blogs$ blogs.php
RewriteRule ^privacy-policy$ privacy-policy.php
RewriteRule ^terms-of-service$ terms-of-service.php
而且,这是我怎么会链接到文章? article.php?id=<?php echo $row_rsBlogs['id']; ?>&slug=<?php echo $row_rsBlogs['slug']; ?>
或article/<?php echo $row_rsBlogs['id']; ?>/<?php echo $row_rsBlogs['slug']; ?>
我使用Dreamweaver,但我很舒适的手工编码。
在此先感谢。
之前'制品只需添加一个斜线。 php'在你的规则。有这样的方式:'RewriteRule^article /([0-9] +)/([^ /] +)$ /article.php?id=$1&title=$2 [NC,L]'。此外,这更好地改变你的第二个例子的链接(即使可以用规则重定向) – 2014-10-04 19:31:11
谢谢贾斯汀!这是完美的!非常感激!我不知道我怎么能给你答案的答案。旁边没有上/下的投票。只要知道你的技巧!谢谢!!!!! – Soletwosole 2014-10-04 20:35:12