0

I would like to redirect www.hostname.com/some path/?cpao=12 to www.hostname.com/some path/?kmas=12.

Essentially replacing the word cpao with kmas and keeping everything else the same.

Any help will be appreciated.

2 Answers 2

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^cpao=([^&]*) [NC]
RewriteRule ^ %{REQUEST_URI}?kmas=%1 [R,L]
Sign up to request clarification or add additional context in comments.

Comments

1
RewriteRule ^hostname.com/somepath/\?cpao([0-9]+)$ hostname.com/somepath/\?kmas=$1

you use regex in htaccess $1 is the numbers that was catched in group 1

4 Comments

Thank you! How would I extrapolate it to be so be it any path i always want cpao substituted with kmas. substitute the string cpao with kmas. Would it be possible to have all that captured in one rewrite rule or should I do more than one?
Yes, as I said it uses regex so you can use this to capture a lower caps path ([a-z]+) replace this with somepath
It won't work because RewriteRule only matches REQUEST_URI after stripping leading slash.
I forgot this Thank you @anubhava

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.