basic questions
2 posts
• Page 1 of 1
basic questions
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]
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]
Re: basic questions
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').
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').
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 18 guests