1

I'm currently using a CMS that rewrites all URLs and currently I have a URL like this:

http://www.domain.com/folder/?user=user1

I'm looking to have that rewrite to: index.php?r=search&term=$1

Would something like this work?

RewriteRule ^/?user=(.*) index.php?r=search&term=$1 [L]

Seems to be giving me trouble. Any suggestions?

1

2 Answers 2

1

The query string is not part of the URI-path test it in the rule. It is at QUERY_STRING variable.

You may try this:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} user=([^/]+)/?  [NC]
RewriteRule ^folder/?  /index.php?r=search&term=%1  [L,NC]
Sign up to request clarification or add additional context in comments.

2 Comments

What is this [^/]? Do you mean [^&]?
@Olaf Good question. I had my doubts about that too, but assume the query string is just as described and eventually could end with a slash, like http://www.domain.com/folder/?user=user1/. That might happen if it is manually entered. Could have used & in case there are more key-value pairs, as you say. Doesn't seem there are, though.
0

try ( not tested)

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^folder1/?user=(.*)$ index.php?r=search&term=$1 [R=301,L]

Comments

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.