K
K
khipster2016-03-12 23:29:07
Apache HTTP Server
khipster, 2016-03-12 23:29:07

What does regular expression mean in .htaccess?

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Let's say the request is: www.site.com/page.html
%1 is of course site.com , and $1 why page.html and not www.site.com/page.html ?
Or does RewriteCond %{HTTP_HOST} sort of convert the URL by itself, truncating www.site.com/ from it ?
All figured out.
There's a catch: When you prefix a lookup field with http://thishost[:thisport] , mod_rewrite cuts it off automatically.
There is actually a whole series of events. RewriteRule sees external redirect and does NOT add RewriteBase, but seeing thishosttruncates www.site.com. You can write it like this, without ^ and $:
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
6
65536, 2016-03-12
@65536

Thank you

V
Viktor Taran, 2016-03-21
@shambler81

%1 - variable from conda
$1 from rewrite rule itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question