basic questions

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 8
Joined: 06 May 2016, 16:24

basic questions

14 Sep 2016, 12:55

My main question is when to start the pattern url with ^ and when to end the url pattern with $

So what is the difference between:
RewriteRule ^free-stuff-freebies.asp /freebies-free-stuff/ [R=301,L,NC,QSA]
and:
RewriteRule /free-stuff-freebies.asp /freebies-free-stuff/ [R=301,L,NC,QSA]
and:
RewriteRule free-stuff-freebies.asp /freebies-free-stuff/ [R=301,L,NC,QSA]

2. I also noticed in some of the examples, there is a $ at the end of the first url pattern.

So what is the difference between:
RewriteRule ^free-stuff-freebies.asp$ /freebies-free-stuff/ [R=301,L,NC,QSA]
and:
RewriteRule ^free-stuff-freebies.asp /freebies-free-stuff/ [R=301,L,NC,QSA]

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: basic questions

15 Sep 2016, 07:15

Hi.

Let me better show you this by the example. Imagine user requests http://www.mycoolsite.com/foo/bar.asp
In this case URL in httpd.conf (global file) will appear as '/foo/bar.asp' - absolute form, but for .htaccess rules context is already stripped, so if .htaccess file is in the root of your website, it will see 'foo/bar.asp', and .htaccess in /foo folder will see 'bar.asp'

Now about ^$, RewriteRule uses search algorithm, so pattern is searched, not matched, i.e.
RewriteRule foo/bar.asp ...
will match '/foo/bar.asp', '/otherfolder/foo/bar.asp' etc. Use '^' to identify the beginning of string and limit matching to 'foo/bar.asp' only. Same for '$' - end of string, as sometimes you need to confirm string ends with '.asp' (use 'bar\.asp$') and sometimes you need to match anything that starts with /foo (use 'foo').

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 23 guests