Questions tagged [rewritecond]
The rewritecond tag has no usage guidance.
135
questions
10
votes
3
answers
30k
views
How do I make RewriteCond %{HTTP_COOKIE} match a cookie value exactly? [duplicate]
How do I make my rule match an exact value of a cookie? I've tried:
RewriteCond %{HTTP_COOKIE} ^its=me$ [NC]
RewriteCond %{HTTP_COOKIE} its=^me$ [NC]
RewriteCond %{HTTP_COOKIE} its="me" [NC]
...
6
votes
1
answer
5k
views
How do I reset Apache's RewriteCond directive?
I have some Apache configuration like this:
# Image hotlinking rule
RewriteCond %{HTTP_REFERER} ^http://badsite\.com/
RewriteRule .*/static/artwork/.*\.(jpg|png)$ /static/images/hotlink.png [L]
# ...
4
votes
1
answer
3k
views
rewrite / restrict specific domain name in apache
We have https://example1.com/login and example2.com/login being hosted from the same apache server (2.2.22). I want to restrict /login on example1.com.
example1.com/login --> 404 (preferably) or 403
...
3
votes
2
answers
17k
views
One RewriteCond for multiple RewriteRules
I need to preserve all user query strings.
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^$ index.html?page=home&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^about$ index.html?page=about&...
3
votes
1
answer
9k
views
Drop trailing slash in apache for directory
I have the following url www.example.com/advice/ now notice the trailing slash at the end of the url? I would like that to be removed to be something like www.example.com/advice. Now when I enter that ...
3
votes
1
answer
905
views
Apache rewrite to extract multiple pieces of data from original request URL
Trying to create an Apache rewrite that applies to video files only, over to a dedicated video-serving web-server.
It requires rewrite logic that extracts multiple pieces of information from the ...
3
votes
3
answers
218
views
Updated SSL certs and now rewrite conditions no longer working for apache2
I'm running an Ubuntu 14.04 server with Apache2 v2.4.7.
Recently our site was getting errors from Chrome saying we needed to update our certs. I just completed that earlier this week, updating the ...
3
votes
1
answer
8k
views
ProxyPass if RewriteCond is TRUE
At proxypass configuration file I have written this line
ProxyPass /directory/ ajp://localhost:8009/directory/
It works perfectly
At htaccess file
RewriteRule ^seconddirectory/(.*)$ http://domain....
3
votes
1
answer
11k
views
How to exclude a sub-folder from HTaccess RewriteRule
I have WordPress installed in my root directory, for which a RewriteRule is in place.
I need to password-protect a subfolder ("blue"), so I set the htaccess in that folder as such.
Problem is that ...
3
votes
1
answer
338
views
Trouble with www. redirect (.htaccess)
I'm trying to get a simple www. to non www. redirect set up. Here's the .htaccess
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.org [NC]
RewriteRule ^(.*)$ http://...
2
votes
2
answers
7k
views
Explanation of new line in htaccess file: RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
Recently I noticed that a new line was added in the htaccess file in several locations throughout the file.
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
I don't ...
2
votes
1
answer
448
views
Apache: Don't log errors for certain non-existing files (regular file or symbolic link)
I want to prevent Apache from logging "File does not exist" errors for certain irrelevant non-existing files that are often requested, such as "apple-touch-icon-120x120.png". These ...
2
votes
1
answer
267
views
apache httpd keep sending http requests to strange IPs
Recently I noticed my server keeps sending data to strange location "121.11.76.48" by netstat -na .
To find out what it is sending , I tried :
tcpdump -i eth0 host 121.11.76.48 -nnvvXSs 1514
And ...
2
votes
2
answers
394
views
.htaccess is stopping a site from works while WP sites does work, why?
I have three sites running in a shared hosting (Bluehost) with a dedicated IP address. The description is as follow:
example.com => this is the main site and domain, is a WP
example.net => this is an ...
2
votes
1
answer
10k
views
How to exclude one subfolder from my RewriteRule Htaccess rules?
I have a .htaccess in my root of website that looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.pl [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z0-9_-]+)\.mydomain\.pl [NC]
...
2
votes
1
answer
149
views
unique .htaccess question about mod_rewrite and RewriteCond
I have a few rewrite rules like these
RewriteRule ^dir/(.*)-something.html otherdir/file1.php?var1=val&var2=$1 [L,NC]
RewriteRule ^dir/ otherdir/file2.php?var1=val [L,NC]
dir/ is not a real ...
2
votes
1
answer
795
views
RewriteMap inside RewriteCond doesn't work (Apache)
I have a RewriteCond that checks if {QUERY_STRING} contains the right version number, if it doesn't then redirect users to the correct version.
For instance if v0.7 is the latest, users accessing http:...
2
votes
1
answer
4k
views
GeoIP: Redirect all but specific countries
I am using Apache's GeoIP module and a MaxMind database to determine the country of a visitor based on their IP address and redirecting them to a country sub-folder as shown below:
RewriteCond %{ENV:...
2
votes
1
answer
998
views
Nginx: After removing .html suffixes, how to redirect all requests to the new URLs?
I want to optimize the link structure of an older Magento shop system. Until now, when generating the static pages, a .html suffix was added to the corresponding path. Due to an earlier problem, paths ...
2
votes
0
answers
277
views
Multiple rewritecond with different variables
I am trying to match on two different things in a single request to proxy a request to a different server.
My rewrite conditions are:
RewriteCond %{QUERY_STRING} (token=.*)$
RewriteCond %{...
2
votes
0
answers
413
views
Rewrite rule loses query parameters
I have a webserver running apache2 with php7.
In my apache config, there is a redirect rule like the following:
RewriteCond %{HTTP_HOST} !^www.*
RewriteRule .* %{HTTP:X-Forwarded-Proto}://www.%{...
2
votes
1
answer
155
views
Something like foreach in htaccesss?
I am in this situation:
url: domain/var1/var2/var3/.../varn
And I want to change that url in:
url: domain?v1=var1&v2=var2&v3=var3/.../&vn=varn
I found this way:
RewriteRule domain/([^/...
1
vote
2
answers
2k
views
Unsure what this .htaccess set of rules is doing
I've inherited a web application, and in it is the following set of .htaccess rules. It appears to me that they do nothing. Can someone explain what they're doing?
To me, it looks like they're ...
1
vote
1
answer
15k
views
RewriteCond not matching on my IP when matching on %{REMOTE_ADDR} [duplicate]
I want a mod_rewrite rule not to be executed when traffic is hitting the web-server from internal network. The web server is an apache 2.2
The following RewriteCond is meant to guard the rewrite rule.
...
1
vote
1
answer
14k
views
Multiple RewriteCond doesn't work
I have in htaccess some like this:
RewriteCond %{HTTP_HOST} !^foo
RewriteCond %{HTTP_HOST} !^bar
RewriteCond %{HTTP_HOST} !^some
RewriteRule ^register,(.*)$ /register.html [R=301,L]
RewriteRule ^...
1
vote
2
answers
1k
views
htaccess .html rewrite exception
Ok guys I need to add an exception! How can I do this?
I currently use RewriteRule ([^.]+).html $1 [R=301,L]
to rewrite all .html urls
I do need the exception for the google.html verification file. ...
1
vote
1
answer
328
views
htaccess rewrite rule not working with file extentions
I have two domains setup on the same folder on a server.
i.e.
dl.d123.com @ /var/www/public_html/dl.domain123.com
dl.domain123.com @ /var/www/public_html/dl.domain123.com
I have an htaccess file ...
1
vote
1
answer
3k
views
Redirect all the traffic from multiple domains to single domain using htaccess
I have hosted multiple websites on my server all sharing the same code base having one htaccess.
I need something like this.
if (domainname != example.com) redirect to example.com
if there any ...
1
vote
1
answer
657
views
Nginx try_files instead of IFs to accomplish conditional logic
I'm trying to create Nginx vhost configs that will include the equivalent of the Apache htaccess rewrite rules for OpenCart. Here is the orignal:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
...
1
vote
2
answers
3k
views
How to rewrite URI from root if file doesn't exists in folder?
I have a static folder which is not in my document root. I would like to redirect all the files that are not present in document root, but are present in the static folder. (So if the same file is in ...
1
vote
2
answers
151
views
How to use mod_rewrite to abstract get request with subdomains
I've been at this all day and I thought I had a handle on regular expressions but I'm no longer confident that I do. I've searched all over, read through some horrible guides on mod_rewrite and I'm ...
1
vote
1
answer
499
views
Apache2 - Forward a value from URL param OR cookie, whichever is present
I managed to use apache to strip off a url param and stuff it in a header to be passed on to another server. See this question for reference.
Now I would like to add to this by getting the value for ...
1
vote
1
answer
10k
views
Apache mod_rewrite to return a 404 except one directory
I'm trying to configure Apache to return a default 404 page when the / of DocumentRoot is called, except for some directories in that DocumentRoot
Unfortunately, I'm getting a 404 even for the ...
1
vote
2
answers
141
views
Lazy Conditional Rule not doing anything! Why?
I am rewriting php generated thumbnails with igly urls into nice ones. instead of img.php?src=bla.jpg&w=200&h=100 the static filenames IMG-file_w200_h100.jpg
Because the rewrite is so ...
1
vote
1
answer
2k
views
Should I escape slash '/' in RewriteCond?
Whether I need to escape the slash '/' in RewriteCond?
Currently I write the following rule in .htaccess:
RewriteCond %{QUERY_STRING} rp=/knowledgebase/
RewriteRule ^index\.php$ https://www.datanumen....
1
vote
1
answer
354
views
Rewriterule not working with Joomla urls due to question mark and other special characters, also due to long urls
So I moved from Joomla CMS and now I need to finish my permanent redirects, but the following redirect isn't working (it's actually returning an error 404):
RewriteCond %{HOST_NAME} =&?$
#...
1
vote
1
answer
635
views
Apache doesn't match rewritten URL as regular file
I've setup a .htaccess to redirect requests against the containing directory /htdocs/foo to the file bar.php.
1st of all: I know how to achieve this in general, but for reasons out of my control the ....
1
vote
1
answer
20k
views
Nginx location match if not equal
I have www.example.com/test and i want to write a condition if requested url is not equal to /test do a rewrite or redirect to www.example.com. The closest i can get is a code below but when i want to ...
1
vote
1
answer
7k
views
Why are Apache Rewrite Conditions not working?
I tried to perform a redirect writing in .htaccess file:
RewriteEngine on
RewriteRule article-1 www.another-site.com/article-1 [R=301,L,NC]
and it works correctly. Anyway, when I add a rewrite ...
1
vote
1
answer
1k
views
htaccess file to perform specific rules to different domains [duplicate]
I have one application with is server over a number of domains (each customizes the appearance of the application.
In addition, there is a common domain which has multiple subdomains to display the ...
1
vote
2
answers
11k
views
to set RequestHeader in apache httpd server is not working
I have a requirement, where I need to set the RequestHeader with a value retrieved from the querystring of the URI.
Approach adopted is to write the RewriteCond and ReWriteRule where
the condition ...
1
vote
1
answer
140
views
URL rewriting a specific directory
I want to rewrite the URL when receiving a request that is not a file and either for directory subdir or not a directory at all.
E.g. (!file) && ( (subdir ) | ( !directory ) )
Here's my ....
1
vote
2
answers
3k
views
VirtualHost Redirect should work with new RewriteBase
Inside the VirtualHost I got this redirect:
RewriteBase /
RewriteCond %{REQUEST_URI} wp-content/uploads/([^.]+\.(jpe?g|gif|bmp|png))$
RewriteRule (.*) http://example.org/$1 [R=301,L,NC]
So the full ...
1
vote
1
answer
646
views
RewriteCond always match incorrectly
If I write:
<?php
echo "SCRIPT_NAME: ".@$_SERVER['SCRIPT_NAME']."<br />";
?>
SCRIPT_NAME: /index.php
The line above is showed.
I'm using these rewrite lines
RewriteCond %{SCRIPT_NAME} ...
1
vote
1
answer
2k
views
phpMyAdmin rewrite for nginx
I am trying to configure Nginx so that I can access PhpMyAdmin from a subdirectory (aka domain.com/phpmyadmin). The code provided below seems to work for me although I don't want the alias to be /...
1
vote
1
answer
433
views
RewriteCond for multiple files
In htaccess file, RewriteCond for one file bla.php can write so right?
RewriteCond %{REQUEST_FILENAME} !bla.php
Question: how can write RewriteCond for multiple files? for example for 3 files: bla....
1
vote
2
answers
126
views
Serve PHP page in web root but show contents in subdirectories
I have a web site on a shared hosting server. My directory layout looks like this
/home
/user
/public_html
/pics
/family
There is an index.php file in ...
1
vote
2
answers
4k
views
htaccess with conditional rewritebase
I have a site (the-tack-shop.co.uk) in which I'm testing my e-commerce framework on. I was trying to test payment using a shared SSL: https://web43.secure-secure.co.uk/the-tack-shop.co.uk/.
I had to ...
1
vote
2
answers
9k
views
RewriteCond in .htaccess file gives me bad flag delimiters
I'm upgrading a website and I use this .htaccess file to show maintenance page:
#MAINTENANCE-PAGE REDIRECT
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting ...
1
vote
1
answer
67
views
Apache VHost Redirect /dir/ to subdomain
I had applications running on the following variable links:
www.example.com/topics/vardir/show
www.example.com/education/topics/vardir/vardir/show
www.example.com/literacy/topics/vardir/show
www....