2016-09-20 162 views
0

我有一個完美的工作htaccess的重寫刪除斜線

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L] 
RewriteRule ^([^/]*)\/$ /social/user.php?user=$1 [L] 

例以下重寫規則:http://myurl.com/username/http://myurl.com/social/user.php?user=username

我想從第二重寫規則刪除斜線,這樣它會返回如下:

實施例:http://myurl.com/username指向http://myurl.com/social/user.php?user=username

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

問題是,當我這樣做,整個域被重定向

這樣: http://myurl.com/http://myurl.com/social/user.php?user=

http://myurl.comhttp://myurl.com/social/user.php?user=

很顯然,我不希望這些最後發生兩件事情。我如何修改我的htaccess以實現預期的結果?

回答

1

試試這個,

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L] 

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

這有助於這麼多謝謝。這不是確切的結果,但條件陳述絕對讓我分類。 – Bruce