Forum Moderators: phranque
Ok so here is my attempt (doesnt work) :(
RewriteEngine on
RewriteLog "c:\urlrewrite.log"
RewriteLogLevel 9
RewriteRule ^(/+) [E=URL:$1]
RewriteRule /index.php [R]
Ok, laugh all you want. I know, I deserve it.
RewriteEngine on
RewriteLog "c:\urlrewrite.log"
RewriteLogLevel 9
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^/(.+)$ /index.php [E=URL:$1]
I'm assuming this is from your httpd.conf file... if it's from an .htaccess file, then remove the slash (/) in "^/(.+)$"
[edited by: jdMorgan at 10:15 pm (utc) on July 20, 2005]
[edit reason] Fixed dropped space before "!" w/bold tags [/edit]
[domain.com...]
I'm trying to get url part 'test' into an ENV variable and have the request for [domain.com...] redirected to index.php or some other file, so i can process the ENV variable.
I'm assuming this is from your httpd.conf file... if it's from an .htaccess file, then remove the slash (/) in "^/(.+)$"
Do you get an entry in your error log?
Have you tested with a simple rule, like
RewriteRule ^/silly\.html$ /index.php [L]
Jim
I got it working almost the way I want:
RewriteEngine onRewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{HTTP_HOST} ^www.mydomain\.net$
RewriteCond %{REQUEST_URI}!^/index.php$
RewriteRule ^(.+)$ http://www.mydomain.net/g.php?uid=$1 [R]
RewriteCond %{HTTP_HOST} ^mydomain\.net$
RewriteCond %{REQUEST_URI}!^/index.php$
RewriteRule ^(.+)$ http://mydomain.net/g.php?uid=$1 [R]
It works, except I can't figure out how to properly detect if the request is coming from www.mydomain.net or just mydomain.net. The second set of RewriteCond works, but the third set of RewriteCond doesn't. I can't figure out why.
There are only two sets of RewriteConds in the code you posted. RewriteConds are ANDed (unless you use the [OR] flag, and apply to the first RewriteRule that follows them, regardless of intervening blank or comment lines.
Therefore your checks for file exists and directory exists at the top apply only to the first RewriteRule. You will have to duplicate those RewriteConds if you wish them to apply to the second rule as well.
Also note that checks for file/directory exists are slow, since mod_rewrite must call your filesystem manager to do the check. If you use them, try to make those checks the last RewriteCond before the RewriteRule. When this is possible, it will improve the performance of your site.
Further, I recommend that you do not end-anchor domain names in the RewriteCond patterns. Any user-agent that appends a port number (e.g. example.com:80) will break your rule if it is end anchored.
Jim
You may need to add RewriteCond(s) to prevent images, CSS, JS, /w3c/p3p.xml, and robots.txt from being rewritten, but this is still far more efficient than doing file-exists checks.
By making the "www." in the first RewriteCond optional as shown, the second ruleset can be eliminated.
Also, using the [R] flag and a canonical URL in the substitution will result in an external redirect, which will "expose" your rewrite and cause your php pages with parameters to be listed in search results. This is usually very undersirable. I have therefore changed the RewriteRule to do an internal rewrite only.
Taking into account my note about anchoring domain names in the previous post above, this gives:
RewriteCond %{HTTP_HOST} ^[b](www\.)?[/b]mydomain\.net
RewriteCond %{REQUEST_URI} !^[b]/g\.p[/b]hp$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦¦png¦js¦css)$ [NC]
RewriteCond %{REQUEST_URI} !^/(w3c/p3p\.xml¦robots\.txt)$
RewriteRule ^(.+)$ [b]/g.php?uid=$1[/b] [L]
Jim
Your code works, except for this part:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.net
So I tried to change it to:
RewriteCond %{HTTP_HOST} ^mydomain\.net [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.net [OR]
But that didn't work either. Basically, the rule doesn't work if I go to [mydomain.net...] but it does work if I put in the www.