2015-04-14 120 views
1

我試圖和谷歌搜索幾個小時了,無法找到我的問題的解決方案。我想重寫:htaccess重寫規則,沒有斜槓

domain.com/profile.php?user=abc> domain.com/abc

我用:

RewriteRule ^(.*)/$ /profile.php?user=$1 [L] 

只在末端斜線的作品。如果我沒有斜槓嘗試它

RewriteRule ^(.*)$ /profile.php?user=$1 [L] 

我得到一個內部服務器錯誤!

完整的.htaccess

ErrorDocument 404 /errors/404.php 
ErrorDocument 500 /errors/500.php 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$ 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] 
RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L] 
RewriteRule ^(.*)/$ /profile.php?user=$1 [L] 
<IfModule mod_deflate.c> 
<FilesMatch "\.(html|php|txt|xml|js|css|svg)$"> 
SetOutputFilter DEFLATE 
</FilesMatch> 
</IfModule> 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html 

Someboy有一個想法是什麼林做錯了什麼?

感謝, 科內爾

回答

0

隨着你的第二次嘗試,你會得到一個500,因爲你創建一個無限循環:
^(.*)$會一次又一次地匹配profile.php?user=xxx ...這是不是這樣的,當你試圖用^(.*)/$因爲(沒有尾隨斜線),這將不匹配profile.php?user=xxx

相反,你可以把它這樣

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] 
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$ 
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] 

RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/?$ /profile.php?user=$1 [L] 
+0

釷爲你提供幫助。隨着你的方式請求正常工作,但URL被改回'profile.php?user = xxx' –

+0

這很奇怪。很難知道爲什麼,也許是因爲你可能有其他規則?你可以看看http標題,並告訴我當你嘗試你的鏈接時發生了什麼? –

+0

嗯非常奇怪,現在它的工作。 有沒有辦法得到這兩個選項,**/**和沒有**/**和結束? –