2012-10-31 57 views
1

所以我想從.htaccess文件通常的事情。 www.example.com/article.php?title=my_title應該替換爲www.example.com/article/my_title,但我似乎無法使其起作用。截至目前,我可以讓.php下降,我懷疑這可能是一些問題。 (我也得到http://example.comhttp://www.example.com)這是我的.htaccess文件.htaccess文件mod_rewrite乾淨的網址不工作

Options +FollowSymLinks -MultiViews 
rewriteengine on 

## this is the piece that is not working 
RewriteRule ^title/(.*) article.php?arr=title/$1 

rewritecond %{HTTP_HOST} ^example.com$ 
rewriterule ^example\/(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301] 

RewriteBase/

## Hide .php extension 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule^%{REQUEST_URI}.php [L] 

## Error document (needs to have a 404 page created) 
ErrorDocument 404 http://www.example.com/ 

回答

1

您需要添加這些特定的路由規則以前普遍適用於PHP文件的任何規則。因此,只需在您的rewriteengine on下,添加:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/article\.php\?title=([^&\ ]+) 
RewriteRule^/article/%1? [L,R=301] 

RewriteRule ^/?article/(.*)$ /article.php?title=$1 [L] 

然後您的其餘規則。

+0

我想我通過添加建議的代碼來獲得重定向循環,有什麼我需要改變? – kqlambert

+0

@kricket你打算導致循環或500錯誤的URL是什麼?我把所有這些放在一個空白的htaccess文件中,並且我沒有使用測試每個規則的URI的任何問題。 –

+0

www.example.com/article.php?title=something然後它正確地將我帶到www.example.com/article/something但是,這給我一個500內部服務錯誤。 – kqlambert