2014-09-23 81 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