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

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 ...


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

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 ...


3

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


2

The purpose of that particular RewriteCond is to prevent requests for nonexistent static files being passed in to OpenCart. You can do this with another location. For instance (off the top of my head, so it may need tweaking): location ~ \.(ico|gif|jpg|jpeg|png|js|css)$ { try_files $uri =404; }


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

It doesn't need to be more complicated than RewriteCond %{HTTP_COOKIE} /^(.*;)?its=me(;.*)?$/ Note that if the cookie value contains special (not URL-safe) characters, Krist van Besien's solution probably works best.


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

I found the answer to my question. The correct condition should have been: RewriteCond %{REMOTE_ADDR} !192\.168\.[0-9]+\.[0-9]+


1

What you're looking for is the [P] flag of RewriteRule. Something like this: RewriteCond %{HTTP_HOST} ^alias.domain.com$ [I] RewriteRule ^/(.*)$ http://myinternalserver.com/$1 [P,L]


1

The Apache variable you want is called %{SCRI­PT_­FIL­ENAME}. In PHP's $_SERVER super global, both SCRIPT_NAME and SCRIPT_FILENAME exist but in Apache, only %{SCRIPT_FILENAME} exists. It's not clear from the documentation exactly what each of the PHP variables contains but in my testing, SCRIPT_FILENAME is a full filesystem path and SCRIPT_NAME is either ...


1

Record the SSL session with WireShark, then check the SSL ALERT protocol. This will help you understand the negotiation. Enable SSL debugging on the apache server. Check if the apache server is requesting the client to renegotiate the session and that the client is sending the certificate. If needed you can also decrypt the session if you have the server's ...


1

It is how i did it Added the bellow code to root folder .htaccess Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^(abx/xyz.html)/?$ $1/index.php [L,NC] And added the bellow code to the .htaccess file in side the xyz.html folder DirectorySlash Off Directoryindex index.php Options -Indexes



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