7

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


4

Try something like this. RewriteCond %{REQUEST_FILE} !-f RewriteRule ^(.*)$ http://site2.com/$1 [QSA,R,L]


4

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.


4

If you remove the slash on a directory and still expect the directory index document (in that directory) to be returned then you'll need to manually "fix" the URL by internally rewriting to the index document. (You basically need to redo what you have undone by turning the DirectorySlash Off.) Try something like the following before other mod_rewrite ...


3

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


3

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


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

You can't. What you're trying to do makes no sense.


3

RewriteCond only applies to the next RewriteRule. You now have two rules, each of which need the exception. So just repeat that RewriteCond line like this: #Redirect all /[pagename] requests (with exceptions) to index.php?page=[pagename]&[querystring] RewriteCond %{REQUEST_URI} !^\/(pma*|css) RewriteRule ^([a-z0-9\-_]+)\/{0,1}$ index.php?page=$1 [NC,...


3

Exceptions like this are easier to apply as final rules that don't do any rewriting. Replace your RewriteCond line with: RewriteRule ^pma/ - [L] RewriteRule ^css/ - [L]


3

You are very close to what you like to have, you only missing ( & ) RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.com$ RewriteCond %{REQUEST_URI} \.(mp4|mp3|mov|mpg|mpeg|webm|wmv|ogg)$ [NC] RewriteRule ^/(.*)$ https://www.webvideo.com/%1_video/$1 [R=301,NC,L,NE] The point is %1 refers to first Capturing Group in your Rewrite Conditions. Capturing Group are ...


2

Convert comment to CW I got it working with RewriteEngine On RewriteCond %{REQUEST_URI} !^(.*)/dir1(.*)$ RewriteCond %{REQUEST_URI} !^(.*)/dir2(.*)$ RewriteRule (.*) - [R=404,L]


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

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]


2

The reason why that's not working is %{REQUEST_FILENAME} is the full path to the file (see http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond). If I understand correctly what I think you're trying to accomplish, you'd do it with multiple conditions using RewriteCond backreferences. I didn't test this, but I think it'd be something like ...


2

To be more precise, you CAN tell Apache, for instance, to redirect to a certain format, but then (at least some) browsers get confused because it asks for the lowercase version of the domain and gets a redirect to the same domain: Apache actually asks the browser to reformat it's request. Finding an infinite loop, firefox just tells the user the server is ...


2

Your RewriteCond for the *.443 section has an obvious issue with it. HTTPS (typically) runs on port 443 (as the VirtualHost configuration shows) but your rewrite condition says 'If the server port is not 80, redirect to https://...'. So, hit port 443, ask for content, get told to go to 443 because you're not on 80. That's a loop. RewriteCond %{...


2

create .htaccess file for your standalone PHP application that will redirect your code to subsite.example.net


2

What is important is the underlying file/directory structure. If these 3 sites are essentially on the same account - the same parent directory - then each site is probably in a separate subdirectory (which is often how addon and subdomains default in a shared environment) and you should have a separate .htaccess file in each subdirectory. Not one for all. ...


2

As with your other condition, checking for the presence of www in the host, you need to check against the HTTP_HOST server variable again, not REQUEST_URI - which only holds the URL-path. Try the following: RewriteCond %{HTTP_HOST} !^myloadbalancername RewriteCond %{HTTP_HOST} !^www\. RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L] I've also added a ...


2

It removes the slash at the end of any URL e.g.: https://example.com/welcome/ becomes: https://example.com/welcome The second RewriteCond specifies that the rule only matches when the URL does not match an existing directory on the disk, (it could be a file for example) of course, automatically.


2

Just to add to OverCoder's answer... as already stated, this code removes the slash at the end of the URL (except for directories) ... RewriteCond %{REQUEST_URI} /$ RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ $1 [L,R=301] However, the first RewriteCond directive here is indeed superfluous and can be removed. This simply checks that the URL ends ...


2

This isn't really a complete answer, as I can't comment specifically on how/where Ballot169 fits into the bigger scheme of things. However, I can comment on "what it does". It does seem a bit odd though... In general, these RewriteCond directives are used to create exceptions so that when SSL certs are auto-renewed, the necessary validation file can be ...


2

RewriteCond "%{QUERY_STRING}" !^v=${versions:version} This doesn't work because the CondPattern (2nd argument to the RewriteCond directive) is a regex and consequently does not support variable expansion. (Just as you can't use backreferences of the form $n or %n or server variables %(SERVER_VAR} or env vars %{ENV:MY_ENV_VAR} etc.) It would ...


1

This ought to work: RewriteCond %{HTTP_HOST} (.*).domain.com RewriteRule ^/u/([^/]+)/?$ /user.php?user_name=$1&domain_given=%1 [P] Remember how the LHS of the RewriteRule gets tested first. Then in the RewriteCond LHS gets matched against the RHS, and if this matches the substution will take place. Strings you capture in the RHS of a RewriteCond get ...


1

The ?user_name=satbirkira part can be a bit tricky to feed into PHP with a rewrite, depending on how PHP is accessing the data - some applications end up getting the original query string, and not the rewritten one. But, for now, let's start with this and see where it gets us. This should be in VirtualHost context, if it's in <Directory> or .htaccess ...


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


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

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

If I understand right, you're trying to emulate Nginx's try_files functionality, in which case it looks like maybe this will work for you. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://app_cluster%{REQUEST_URI} [P,QSA,L]


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