我使用.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