I am making some changes in .htacess file and i want to capture the requested url, create substring of it and pass it to third part url.
For example
I am working on ubuntu, so currently my .htaccess file is in folder test. So when i access localhost/test/http://www.facebook.com
, it takes me to service.prerender.io/test/http://www.facebook.com
but i want to eliminate the ‘test’ and forwrd the request like service.prerender.io/http://www.facebook.com
Here is the code of my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/script.php
RewriteRule ^(.*)$ http://service.prerender.io%{REQUEST_URI} [L,QSA]
</IfModule>
2
Answers
You can use the
RewriteCond %{REQUEST_URI}
to set capture groups and instead of rewriting tohttp://service.prerender.io%{REQUEST_URI}
you can rewrite to something like thishttp://service.prerender.io/%1
.Here is an example (untested):
What you are trying to captures is not directly the requested uri but part of it. You can get it from rewrite rule
Try following
If you’re accessing a page something like,
Then you will get following as request uri and script uri
And https://github.com/prerender/prerender-apache is more information about htaccess and prerender