htaccess rewrite for one php with all variables

Hi guys,

I am looking for a simple rewrite rule but somehow I dont get this done. I tried already dozens of versions but somehow I dont get it. The only thing I want is

original
http://www.domain.com/folder/file.php?var1=xxx&var2=xxx

to new version
http://www.domain.com/folder/file_new.php?var1=xxx&var2=xxx

But there is the possibility to have only one variable but also could be 3,4 or more. So i need simply with any variable connected one to one.

Thank you
Oliver2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Try the [QSA] Directive

RewriteRule folder/file.php$ folder/file_new.php [L,NC,QSA]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bernard S.CTOCommented:
Not sure that julian's directive works as expected.
As per http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa I would prefer to use a similar rule:
RewriteRule folder/file.php?(.*)$ folder/file_new.php?$1 [L,NC,QSA]

Open in new window

0
Julian HansenCommented:
@fibo
Not sure that julian's directive works as expected.
It will work exactly as expected - that is what the QSA directive is for - it appends the query string to the back of the rewritten request.

While your solution is valid - it is a but of a clunky way of achieving the same end.

The solution presented is the correct way of doing this - to rewrite the filename and ahve the rewrite engine handle the appending of the parameters.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Bernard S.CTOCommented:
Thx Julian, I was not sure!
0
Julian HansenCommented:
@fibo -I did some more testing and in fact you don't need the QSA directive at all. The following will do the job just as well

AddType x-mapp-php5 .php
Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule folder/file.php$ folder/file_new.php [L]

Open in new window

0
Bernard S.CTOCommented:
@Julian,
What disturbs me in both cases is the $ of the rewrite rule...
0
Julian HansenCommented:
The $ just means match to the end of the line - it is nto required.
0
Bernard S.CTOCommented:
If $ means end of line (as I thought) then there are "chances" that anything after php does not match, hence my ?(.*)
0
Oliver2000Author Commented:
Worked perfect for me. Thank you
0
Julian HansenCommented:
You are welcome - thanks for the points.
@fibo
If $ means end of line (as I thought) then there are "chances" that anything after php does not match, hence my ?(.*)
The end of line in this case is end of the domain name - it does not include the query string parameters that come after the filename.
0
Bernard S.CTOCommented:
B-) Thx Julian, added to my bag of tricks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.