Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Rewriterule - what's the difference in this syntax? |
|
Author |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Fri 16 May '08 21:23 Post subject: Rewriterule - what's the difference in this syntax? |
|
|
Hello,
I use following Rewriterule (which works):
RewriteRule (.*) http://www.somedomain.com/$1 [R=301,L]
When I use:
RewriteRule ^/(.*)$ http://www.somedomain.com/$1 [R=301,L]
By using this, some URL's don't work.
Can somebody help me out what the difference is between:
(.*) and ^/(.*)$
Regards. |
|
Back to top |
|
tdonovan Moderator
Joined: 17 Dec 2005 Posts: 611 Location: Milford, MA, USA
|
Posted: Fri 16 May '08 23:35 Post subject: |
|
|
A good technique to understand mod_rewrite problems is to turn on RewriteLog like this: Code: | RewriteLog logs/rewrite.log
RewriteLogLevel 9 |
In your case, the RewriteRule directive is treating ^/(.*)$ as a file-system path, not a URL-path
- so if you request http://localhost/something.html it is matching the pattern "something.html" instead of "/something.html".
This presumes you put your RewriteRule directive inside a <Directory> block.
Whatever leading characters go with that directory are stripped off the pattern. That is why you do not get a leading "/".
If you put your RewriteRule directive outside of any <Directory> block, you will get the leading "/".
-tom- |
|
Back to top |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Sun 18 May '08 20:51 Post subject: |
|
|
Thanks for the info!
I've stumbled across some examples and to redirect to a new domain (and keep all files/folders intact) I see:
RewriteRule (.*) http://www.newdomain.com/$1 [L,R=301]
and sometimes
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
Does this have the same effect? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
alex.w474
Joined: 20 Feb 2008 Posts: 11
|
Posted: Mon 19 May '08 0:13 Post subject: |
|
|
In regular expressions, ^ at the beginning means start of the string and $ at the end means end of the string. For the expression ".*" it should not make any difference, because ".*" and "^.*$" means the same.
For example, expression "witsuite.com" and "^witsuite.com" are different: "witsuite.com" matches any string with word witsuite, followed by any character and this any character followed by com. But "^witsuite.com" matches only the strings started with "witsuite":
RegExp: "witsuite.com"
Match: "witsuite.com", "witsuiteacom", "http://witsuitexcom.com"
RegExp: "^witsuite.com"
Match: "witsuite.com", "witsuiteacom"
Not match: "http://witsuitexcom.com" |
|
Back to top |
|
flatcircle
Joined: 27 Jun 2006 Posts: 79
|
Posted: Mon 19 May '08 19:19 Post subject: |
|
|
Things are making sense now
Thanks for your help guys! |
|
Back to top |
|
|
|
|
|
|