sam
sam

Reputation: 45

How to replace the first parameter name in query string using .htaccess?

I need to change the name of the first parameter in the query string from p (lower case) to P (upper case). It is the first parameter in the query string.

For example, I need to change the url from:

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

to

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

The framework is wordpress.

The .htaccess code:

    # 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>

Upvotes: 0

Views: 760

Answers (1)

anubhava
anubhava

Reputation: 785186

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

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

Upvotes: 1

Related Questions