.htaccess url:重写不能在本地主机上运行

时间:2014-09-23 08:15:06

标签: regex apache .htaccess mod-rewrite url-rewriting

我是.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 个答案:

答案 0 :(得分: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]
相关问题