如何使用.htaccess替换查询字符串中的第一个参数名称?

时间:2015-04-03 09:12:47

标签: .htaccess

我需要将查询字符串中第一个参数的名称从 p (小写)更改为 P (大写)。它是查询字符串中的第一个参数。

例如,我需要更改网址:

http://www.example.com/shop/?p=product_name

http://www.example.com/shop/?P=product_name

框架是wordpress。

.htaccess代码:



    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{QUERY_STRING} ^p=([^&])$
        RewriteRule ^securestore/?$ $0?P=%1 [L,NC,R=302]
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        RedirectMatch 301 ^(.*)/EcoSupp$ $1
    </IfModule>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^p=([^&]+)
RewriteRule ^securestore/?$ $0?P=%1 [L,NC,R=301]