php url rewrite remove?=来自url

时间:2016-03-14 06:07:02

标签: php

我正在使用以下htaccess代码。

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    RewriteRule ^Profile/([0-9]+)/?$ ViewProfile.php?id=$1 [NC,L]

这是网址 http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944

我需要将此网址转换为http://localhost/ConnectMyProfile/ViewProfile/CMP26944

为此,我使用了这段代码(RewriteRule ^ Profile /([0-9] +)/?$ ViewProfile.php?id = $ 1 [NC,L])。

它没有用。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

从您的域开始mod-rewire start。然后在localhost上,如果你想要你的mod_rewrite工作,你应该将它传递给你的项目地址,
在所有上述事情之前,你应该检查你的mode_Rewire是否启用
重定向:
http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944
http://localhost/ConnectMyProfile/ViewProfile?id=CMP26944
http://localhost/ConnectMyProfile/ViewProfile/CMP26944

RewriteEngine On
RewriteBase /ConnectMyProfile/


# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /ViewProfile\.php\?id=([^\s&]+) [NC]
RewriteRule ^ ViewProfile/%1? [R=302,L]

RewriteCond %{THE_REQUEST} /ViewProfile\?id=([^\s&]+) [NC]
RewriteRule ^ ViewProfile/%1? [R=302,L]


# internally rewrites /ViewProfile/ABC123 to ViewProfile.php?id=ABC123
RewriteRule ^ViewProfile/([A-Z,0-9]+)$ ViewProfile.php?id=$1 [L,NC,QSA]

# PHP hiding rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]