Vipin Kumar
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&v ar2=val2&v al3=val3 must be shown in address bar as http://localhost/portal/SCRIPTNAME.php/var1/val1/v ar2/val2/v al3/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
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&v
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
Replace php with a host name
ASKER
@jdmailny,
I did not understand your solution, can you provide bit more information.
Thanks
I did not understand your solution, can you provide bit more information.
Thanks
I think this can probably be done. I'll try to have a look at it tomorrow.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I know some of those regex patterns are pretty hairy... explaining them might be worthy of a separate question though!
ASKER
@Terry,
Doesn't work. Nothing is happening Neither Redirection nor internal redirection
Thanks
Doesn't work. Nothing is happening Neither Redirection nor internal redirection
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Terry,
Works perfectly fine.
Thanks
Works perfectly fine.
Thanks