2014-09-23 37 views
1

上工作,我在我的.htaccess當前URL新是:的.htaccess網址:重寫不是本地的主機

http://localhost/www.zeeshan.com/details.php?p_id=999 

如果我要顯示我的網址是這樣的工作爲我好。

http://localhost/www.zeeshan.com/details/999 

我的.htaccess代碼是

Options +FollowSymLinks -MultiViews 

RewriteEngine On 
RewriteBase /www.zeeshan.com/ 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^details/([^/]+)$ details.php?p_id=$1 [NC,L] 

我的問題是,當使用這個鏈接我無法得到我正確的答案:

http://localhost/www.zeeshan.com/details.php?p_id=999&p_title=nokia%20mobile%20for%20sale 

我用這個.htaccees代碼

Options +FollowSymLinks -MultiViews 

RewriteEngine On 
RewriteBase /www.zeeshan.com/ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^details/(\d+)-([\w-]+)$ details.php?p_id=$1&p_title=$2 [NC,L] 

使用這個鏈接後,我想這樣

http://localhost/www.zeeshan.com/details/999/nokia-mobile-for-sale 

我在給定的鏈接看了很多時間這個話題解決我的問題,但未能得到正確的我放出來。每次和得到找不到頁面錯誤Rewriting URL with .htaccess local in XAMPP

請幫我解決我的問題。

回答

1

你的正則表達式是不正確實際。使用這樣的規則:

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase /www.zeeshan.com/ 

## convert spaces to hyphens 
# executes **repeatedly** as long as there are more than 1 spaces in URI 
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [L,NE] 

# executes when there is exactly 1 space in URI 
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^details/(\d+)/([^/]+)/?$ details.php?p_id=$1&p_title=$2 [NC,L,QSA] 
+0

這給了這樣回答的http://localhost/www.zeeshan.com/details/189/nokia%20mobile%20for%20sale ,但我想我的答案是這樣 HTTP:現在//localhost/www.zeeshan.com/details/189/nokia-mobile-for-sale – 2014-09-23 08:37:57

+0

檢查更新的規則。 – anubhava 2014-09-23 08:42:23

+0

先生任何可能性,如果我有2頁像index.php和detail.php。如果像deatilss.php我的.htaccess錯誤的方式打開用戶頁面detail.php:URL重定向並打開我自己設計的404.php頁面?使用上面的.htaccess代碼 – 2014-09-23 10:17:20