Forum Moderators: phranque
[domain...] goes to [domain...]
and
[domain...] goes to [domain...]
I don't want it to start rewriting my static html and jpg files so included some RewriteCond rules
RewriteCond %{REQUEST_URI} !(.*).htm(.*)
RewriteCond %{REQUEST_URI} !(.*).jp(.*)
RewriteRule ^/(.*)$ /folder1/folder2/$1 [P,NE]
The rule above works ok, only problem is that I have the homepage of my website on [domain...]
and that one gets redirected to [domain...] now with that rule in place.
I have my website on [domain...]
DirectoryIndex index.html
but I've set it up that it also works on just the domain main
What RewriteCond can I use to check that the current url isn't just the homepage on htpp://domain/ ?
Any suggesions ? Thanks
# Internally rewrite non-blank URL paths not containing slashes or periods to /folder1/folder2 subdirectory.
RewriteRule ^([^./]+)$ /folder1/folder2/$1 [L]
BTW, avoid the use of ".*" subpatterns -- and especially multiple ".*" subpatterns whenever possible. While ".*" is an 'easy' regex pattern to understand, it is seldom needed, and often leads to unexpected results because it matches "anything, everything, or nothing."
Use of multiple ".*" subpatterns can also be horribly inefficient, because it forces the matching engine to do multiple back-off-and-retry matching attempts --dozens, hundreds, or even thousands of them in some cases-- trying to find a 'best fit' of the match-string to the pattern.
As a result, it is best to make your patterns as specific as possible, and to use all of the 'tricks' available in regular expressions to match *exactly* what you want to match, and as efficiently as possible. See the regular-expressions tutorial cited in out Apache Forum Charter for assistance with this subject.
Jim
Thanks for your suggestion. I tried to apply that one line rule : RewriteRule ^([^./]+)$ /folder1/folder2/$1 [L]
After restarting apache I was still able to access
[domain...] ALSO WORKED !
But the url
[domain...] didn't go to [domain...] (and I checked, that file does exist, doesn't have an extension though)
Do you know why ? Thanks
Separate problem: All *files* on your server should have filetype, so that the server will know what MIME-type it should indicate when sending the HTTP Content-Type header back to the client. So, the physical file should probably be named "test.html" and the rule should be changed to add that ".html" to the URL-path, as well as adding the subdirectory path "/folder1/folder2" as it does right now.
[added] I missed an important clue in your first post: If you are putting this code into a server config file, and not into .htaccess, and the code is *not* going into a <Directory> container in that server config file, then the code will need to be tweaked:
# Internally rewrite non-blank URL paths not containing slashes or periods to /folder1/folder2 subdirectory.
RewriteRule [b]^/([[/b]^./]+)$ /folder1/folder2/$1 [L]
Jim
[edited by: jdMorgan at 10:02 pm (utc) on July 1, 2009]
I had a look at my apache httpd.conf and for the root all I have is
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
I just noticed that I have the domain in a virtual host:
<VirtualHost 192.168.1.100>
DocumentRoot /var/www/website
and there is NO <Directory "/var/www/website"> declaration. would it use the / one ? ---> <Directory />
Thanks again
RewriteCond %{REQUEST_URI} !(.*).htm(.*)
RewriteCond %{REQUEST_URI} !(.*).jp(.*) Multiple .* patterns are always inefficient, however in this case, since you are not re-using the backreference data elsewhere, they can be completely omitted.
RewriteCond %{REQUEST_URI} !\.htm$
RewriteCond %{REQUEST_URI} !\.jpg$ Be aware these match more than just .htm and .jp - you might want to end anchor these patterns (or you might not - I don't know all your requirements).
You must also escape all periods in patterns.
RewriteCond %{REQUEST_URI} !\.htm$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteRule ^/([^/]+)$ /folder1/folder2/$1 [L]
RewriteCond %{REQUEST_URI} !\.htm$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !^/folder1/folder2/
RewriteRule ^/(.+)$ /folder1/folder2/$1 [L]
The [NE] flag is not needed, and you'll only need [P] if you plan to alias or re-rewrite the output of this rule. [L] is recommended for efficiency, again unless you plan to re-rewrite the output of this rule.
Jim
But I've got around it by adding a Rewriterule at the top:
RewriteRule ^/$ /new/home [P]
yes, I need the [P] because /new/home needs to be rewritten again a bit later on to send the url to another server.
At least it does work.
You've lost me there with loose language, I'm afraid... Please define "the hopepage one" and "doesn't work."
... could be as simple as the fact that ".+" means "match one or more characters, and a URL-path of "/" doesn't contain one or more characters past the "/".
Jim
I have set up a DirectoryIndex and also DocumentRoot, but like I said before the code you gave me works good, just not for when I access [domain.com...]
But I have written a RewriteRule to catch / and put it at the top
... could be as simple as the fact that ".+" means "match one or more characters, and a URL-path of "/" doesn't contain one or more characters past the "/".
Instead of adding "band-aid" rules, try using
RewriteRule ^/(.*)$ /folder1/folder2/$1 [L] RewriteRule ^/(.+)$ /folder1/folder2/$1 [L] You will also have to add another RewriteCond:
RewriteCond $1 !^folder1/folder2/ Jim