Avatar of Vipin Kumar
Vipin Kumar
Flag for India asked on

Generic Rule to Redirect and Rewrite URL using .htaccess

Hi,

I want to redirect and then rewrite my URL (internal forwarding) so that it doesn't show the php extension as well it doesn't show the ?, = and & in the URL.

The solution for that was provided for a single script in the question https://www.experts-exchange.com/questions/28969579/Redirect-and-Rewrite-URL-using-htaccess.html by Terry Woods.

In this question i want to achieve the same but instead of adding Rewrite Rules for every script individually i just add one generic rule which applies to all the scripts. Below is the example.

The URL http://localhost/portal/SCRIPTNAME.php?var1=val1 be redirected i.e. show in address bar as http://localhost/portal/SCRIPTNAME.php/var1/val1 and internally it is forwarded to the actual URL http://localhost/portal/SCRIPTNAME.php?var1=val1

The SCRIPTNAME.php can be any name for ex. "error.php" or "admin.php" etc. as well as there can be multiple $_GET variables in a single URL for ex: http://localhost/portal/SCRIPTNAME.php?var1=val1&var2=val2&val3=val3 must be shown in address bar as http://localhost/portal/SCRIPTNAME.php/var1/val1/var2/val2/val3/val3

Also there is no pattern in the naming of the $_GET variables or values.

Kindly let me know if any more information is required

Thanks in advance
Apache Web ServerWeb Development

Avatar of undefined
Last Comment
Vipin Kumar

8/22/2022 - Mon
jdmailny

Replace php with a host name
Vipin Kumar

ASKER
@jdmailny,

I did not understand your solution, can you provide bit more information.

Thanks
Terry Woods

I think this can probably be done. I'll try to have a look at it tomorrow.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Terry Woods

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Terry Woods

I know some of those regex patterns are pretty hairy... explaining them might be worthy of a separate question though!
Vipin Kumar

ASKER
@Terry,

Doesn't work. Nothing is happening Neither Redirection nor internal redirection

Thanks
ASKER CERTIFIED SOLUTION
Terry Woods

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Vipin Kumar

ASKER
@Terry,

Works perfectly fine.

Thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.