【问题标题】:php url rewrite remove ?= from url [duplicate]php url rewrite remove ?= from url [重复]
【发布时间】:2016-03-14 06:07:02
【问题描述】:

我正在使用以下 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])。

它不起作用。请帮我解决这个问题。

【问题讨论】:

    标签: php


    【解决方案1】:

    for start mod-rewire 从您的域开始。然后在本地主机上,如果你想要你的 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]
    

    【讨论】:

    猜你喜欢
    • 2021-09-24
    • 2014-09-26
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多