Tag Info

Hot answers tagged

5

A RewriteCond line only affects the next RewriteRule that is processed. It does nothing on its own. Since there is no RewriteRule following it in the snippet of your config you have given us, my best guess is that the RewriteCond is doing nothing. A quick change that should block anything not sending the correct Host: header: RewriteCond %{HTTP_HOST} ...


4

Line breaks are completely inconsequential; a RewriteCond only ever applies to one RewriteRule; the one directly below it. Providing more information about your configuration would be helpful, as context is relevant in Apache. But, from the fact that your second RewriteRule works, it seems that this configuration is either set in a <Directory> ...


4

A very quick "cheat" is to create a .htaccess in the guests folder with the content <IfModule mod_rewrite.c> RewriteEngine off </IfModule> That will turn off rewrite for the folder in question (and any subfolders)


3

I think if you put a $ at the end of dir/ it will do the trick (note that I haven't tested this, so please try it out before voting me up or anything). The $ means "end of string" in the same way that ^ means "beginning of string". RewriteRule ^dir/$ otherdir/file2.php?var1=val [L,NC] Good luck! --jed


3

For your three examples, these will work: RewriteRule ^$ index.html?page=home [QSA,L] RewriteRule ^about$ index.html?page=about [QSA,L] RewriteRule ^contact$ index.html?page=contact [QSA,L] The trick is the "QSA" flag. edit: a slightly more-general solution, this based on how Drupal does it: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond ...


3

What you have isn't working because backreferences (like $1) in a RewriteCond refer to groups in the last matched RewriteCond rather than the RewriteRule. Try the following instead: RewriteCond %{REQUEST_URI} !^/google(022e525bdb654772|b5e92d18c6640aeb)\.html RewriteRule ([^.]+).html $1 [R=301,L]


3

Try this: RewriteEngine On RewriteCond %{REQUEST_URI} !^/en/ RewriteRule /(.*) /en/$1 [L,R=301]


2

This might not be the only issue (I've never done cookie matching in mod_rewrite before); but I think it's because your backreference for the RewriteRule is still %2. You only have one parenthesised match in the previous RewriteCond, so it expands to nothing. Try [E=memberUuid:%1,P]


2

In the example that you've given, you will most certainly not be redirected. However, it looks like you're expecting the RewriteCond directives to apply to both of the RewriteRule directives - they do not. They only apply to the RewriteRule that immediately follows them. So, in your example, http://foo.domain.com/register,one.html will not redirect you - ...


2

RewriteCond %{HTTP_HOST} ^website\.(com|org|net)$ RewriteRule ^$ en/home [R=301,L] Also a better way of writing all of them: RewriteCond %{HTTP_HOST} ^website\.(fr|de)$ RewriteRule ^$ %1/home [R=301,L] RewriteCond %{HTTP_HOST} ^website\.(com|org|net)$ RewriteRule ^$ en/home [R=301,L] Just for another note, you can combine multiple RewriteCond's as 'or' ...


2

Put the below .htaccess file into /var/www/alpha.com/: RewriteEngine On RewriteCond %{REQUEST_URI} ^/beta/?$ RewriteRule ^.*$ http://beta.com [L] RewriteCond %{REQUEST_URI} ^/beta/(.*)$ RewriteRule ^.*$ http://beta.com/%1 [L] question mask ?: makes the preceding token optional L flag: means the last rule


1

1) You can get this one for free by adding a DirectoryIndex index.php in your .htaccess file that's sitting in public_html. 2) To reroute requests to /pics, you can use this set of rewrite rules: RewriteRule ^pics/?$ http://www.domain.org/ [R,L] 3) You'll need to use the with Options: <Directory "/home/user/public_html/pics/family"> Options ...


1

First advice: use proper lower/uppercase: RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://domain2.com/$1 [R=301,NC,L] Then maybe you forgot the "L" for "Last rule". When you say "it won't redirect any folders e.g. domain.com/folder/ won't redirect to domain2.com/folder/" please explain what it gives, what it should give, and what it ...


1

Apache is perfectly capable of doing what you are asking, however, the RewriteBase directive is not the prescribed way of achieving your desired results. You have two options: Instead of using RewriteBase, just specify the base path in your RewriteRule declarations Create separate NameVirtualhost declarations instead of relying upon a catch-all


1

You can use multiple lines and [OR] flag like samarudge told you, but since you only have slightly different paths, here's a reminder: ReWriteCond/Rule supports regular expressions, so format like this is possible, too: RewriteCond %{QUERY_STRING} !^/var/log/syslog-ng/(JBoss|Tomcat).*$


1

I made this work with multiple URLs (and Andrews help), with the below. RewriteCond %HTTPS off RewriteCond Host: (?!^www.+)(.+) RewriteRule /(.*) http\://www.$1/$2 [I,RP]


1

Instead of putting those rules in the _default_ vhost, put them in the /etc/apache2/sites-enabled/jenkins vhost, so that it can work against requests that have been mapped to that name. Also - the expression on your second RewriteRule won't ever match /jenkins/, since it's requiring at least one character before the leading slash. Try this: ReWriteCond ...


1

This is correct for SEO. Search engines will update their database that the old URL has changed to the new URL. You should leave it active like that for at least several months to they all get a chance to update, and visitors can still use the old URL.


1

I believe you have to use the [OR] flag to chain rules like this: #MAINTENANCE-PAGE REDIRECT RewriteEngine on RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR] RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR] RewriteCond %{REQUEST_URI} !^/maintenance\.html$ RewriteRule ^(.*)$ http://www.mysite.no/maintenance.html [R=307,L] In the apache docs, it's at the ...


1

Try: RewriteCond %{REQUEST_URI} %/IMG.*$ [NC]


1

The RewriteCond is actually processed after the RewriteRule matches! Here's a diagram from the Apache docs:


1

Beside the fact that you can use QSA, are you aware that you can use %{QUERY_STRING} right within your RewriteRule?: RewriteRule ^$ index.html?page=home&%{QUERY_STRING} RewriteRule ^about$ index.html?page=about&%{QUERY_STRING} RewriteRule ^contact$ index.html?page=contact&%{QUERY_STRING} The advantage of this method over the QSA flag is that ...


1

In your RewriteCond you have a backreference ($1). But in order to use a backreference, you first have to capture something to put in it. Try something like this: RewriteCond %{REQUEST_URI} ^/(.*).js$ RewriteCond %{DOCUMENT_ROOT}/AT_%1.js -f RewriteRule ^(.*[^/])/?$ %{DOCUMENT_ROOT}/AT_$1.js [QSA,L] What happens above is that the first condition checks ...


1

In mod_rewrite you can chain more conditions - by default they are connected by logical AND but you can change in with rewritecond's switch OR like this: RewriteCond %{REQUEST_FILENAME} !bla.php [OR] RewriteCond %{REQUEST_FILENAME} !somebla.php


1

Try enabling logging to get a clear idea of what steps are failing: RewriteLog /path/to/log RewriteLogLevel 2 You can use values greater than 2 for the log level, but keep in mind that this will affect your server's performance, so be wary of running this on a heavy production instance. Now, for some security thoughts. If you're worried enough to ...


1

You should use an alias instead: location /mysecretdirectory { alias /usr/share/phpmyadmin/; }


1

Add [L] to the line where you rewrite to subfolder.


1

You need to add the PT flag to your RewriteRule: RewriteCond %{REQUEST_URI} !\.php$ [NC] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule . %{REQUEST_URI}.php [PT] The reason is that the substitution in a RewriteRule is normally assumed to be a file path, not a uri, and thus directives like Redirect etc. are not applied. The PTflag (pass through) tells ...


1

From the online docs: '=CondPattern' (lexicographically equal) Treats the CondPattern as a plain string and compares it lexicographically to TestString.True if TestString is lexicographically equal to CondPattern (the two strings are exactly equal, character for character). If CondPattern is "" (two quotation marks) this compares TestString to the ...


1

There could be of course several cookies, and they can be URL escaped, making comparisons tricky. Something like this ought to work in most cases: RewriteCond %{HTTP_COOKIE} its=([^;]+) RewriteCond %1 ^me$ RewriteRule ...... If you need to unescape the cookie you can add a rewritemap for that: RewriteMap unescape int:unescape ...



Only top voted, non community-wiki answers of a minimum length are eligible