How to catch all characters after domain name as one parameter with mod_rewrite?
I have script which load other page content and displays that like standard page.
example script address look like that:
example.com/script.php/?www='/some/paths/etc'
I want to mask that URL to look like this:
example.com/some/paths/etc
If no paths exist it should look like
example.com/
There can be different amount of URL parts (a/b/c/…/X/)
I red about mod_proxy but I can do it with only .htaccess so it doesn’t solve my problem.
I can’t redirect one address to other, they have to be separated.
You can proxy via
mod_rewrite(as long asmod_proxyhas been compiled into the server), and this can be done via .htaccess files. Note thatRewriteEngine OnrequiresOptions FollowSymLinksto be overridable in your .htaccess.The following in your .htaccess file:
The
RewriteCondmatches your script path with a ?www= argument (if it fails to match no rewrite will take place). The firstRewriteRulewill match the www= argument and rewrite the visible path of the request. The secondRewriteRulewill then proxy the request (due to the [P] flag) to the script and will get the “content”.Note: this has not been tested, but hopefully will get you heading in the right direction to solve the problem. Also if script.php expects optional args
&var2=whateveryou will probably need to tweak theRewriteCondto match that and store it using parentheses. You can then recall those args using %1. More details can be found in the documentation.Also to help you debug your rewriting you can use:
EDIT: Added the
RewriteLogstuff an clarified that the snippet at the top is to be put in the .htaccess file