Link to home
Start Free TrialLog in
Avatar of Vipin Kumar
Vipin KumarFlag 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
Avatar of jdmailny
jdmailny

Replace php with a host name
Avatar of Vipin Kumar

ASKER

@jdmailny,

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

Thanks
Avatar of Terry Woods
I think this can probably be done. I'll try to have a look at it tomorrow.
SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I know some of those regex patterns are pretty hairy... explaining them might be worthy of a separate question though!
@Terry,

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

Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Terry,

Works perfectly fine.

Thanks