3

I search many topic about htaccess but still not success.

I want when people type address:

http://domain.com/?q=filename1
http://domain.com/?q=filename2
...

It will auto redirect to:

http://domain.com/download/filename1.html
http://domain.com/download/filename2.html
...

I try:

RewriteEngine On
RewriteRule ^/?q=(.*)$ /download/$1.html [L,R=301]

But it is not working. How can I fix this?

1

1 Answer 1

7

Using this may be helpful:

RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule ^q(.*) /download/%1.html [L,R=301]

EDIT:

Try this :)

RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule ^(.*) /download/%1.html? [L,R=301]

By using ? query string will be removed ;)

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Mehrnaz K. But it redirect to domain.com/download/filename1.html?q=filename1 and not exist
Please fix, If with ?q=filename1 it doesn't show content and says: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
Hi Mehrnaz K. New code is not working, it is still domain.com/?q=filename1 (not redirect). Please help
@LoveKen, sorry, this new one works well, please test it, thanks

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.