5
votes
Drop trailing slash in apache for directory
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 ...
- 12.1k
5
votes
Accepted
Apache: Don't log errors for certain non-existing files (regular file or symbolic link)
If you are getting "File does not exist" messages in your "error log" then the LogLevel (as set in the server config) is arguably set "too high". Certainly, too high for ...
- 12.1k
4
votes
Accepted
Explanation of new line in htaccess file: RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
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 ...
- 12.1k
3
votes
Accepted
Apache rewrite to extract multiple pieces of data from original request URL
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 ...
- 171
3
votes
Why doesn't this .htaccess file redirect properly?
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]
- 606
3
votes
Why doesn't this .htaccess file redirect properly?
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 ...
- 1,098
3
votes
how to give subnets for IP addresses in rewrite condition?
You can't. What you're trying to do makes no sense.
- 115k
2
votes
Accepted
Nginx try_files instead of IFs to accomplish conditional logic
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 ...
- 241k
2
votes
Accepted
how would i create rule for a particular subdomain in uppercase? e.g XX.test.com
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 ...
- 58
2
votes
Apache mod_rewrite to return a 404 except one directory
Convert comment to CW
I got it working with
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)/dir1(.*)$
RewriteCond %{REQUEST_URI} !^(.*)/dir2(.*)$
RewriteRule (.*) - [R=404,L]
Community wiki
2
votes
apache: prepend a string literal to a TestString in a RewriteCond for mod_rewrite
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 ...
- 1,308
2
votes
Accepted
.htaccess is stopping a site from works while WP sites does work, why?
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 (...
- 12.1k
2
votes
.htaccess is stopping a site from works while WP sites does work, why?
create .htaccess file for your standalone PHP application that will redirect your code to subsite.example.net
- 1,964
2
votes
Accepted
Unsure what this .htaccess set of rules is doing
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} !-...
- 12.1k
2
votes
Unsure what this .htaccess set of rules is doing
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 ...
- 143
2
votes
Accepted
Add www to domain but not for a specific domain
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 ...
- 12.1k
2
votes
Accepted
GeoIP: Redirect all but specific countries
You could simply use negation ! to redirect anything but China CN and Russia RU.
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(CN|RU)$
RewriteRule ^(.*)$ https://example.com/us/$1 [L]
- 44.8k
2
votes
Accepted
RewriteMap inside RewriteCond doesn't work (Apache)
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 ...
- 12.1k
2
votes
Accepted
htaccess rewrite rule not working with file extentions
The reason is the following block in nginx configuration:
location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|...
- 36.1k
1
vote
Nginx location match if not equal
Nginx If
Generally with Nginx you avoid using the IF statement. It takes more resources and doesn't always work how you want.
Solution
The way you do this is to define two locations, catchall and ...
- 31.2k
1
vote
Updated SSL certs and now rewrite conditions no longer working for apache2
Troubleshooting suggestions:
Please confirm your environment:
Ubuntu 14.04 server with Apache2 v2.4.7.
Your httpd.conf is configured to serve both HTTP (:80) and HTTPS (:443).
Your certificate ...
- 270
1
vote
Updated SSL certs and now rewrite conditions no longer working for apache2
On your <VirtualHost *:443> you enable HSTS. That tells the browser to internally rewrite every request for the domain to HTTPS. After this, there's no use for the RewriteCond %{REQUEST_URI} !^/...
- 44.8k
1
vote
Why are Apache Rewrite Conditions not working?
The WordPress directives are at the bottom of the .htaccess file, while I've put mine at the top.
That is correct.
RewriteCond %{HTTP_REFERER} domain.tracker.com [NC]
There is nothing actually ...
- 12.1k
1
vote
Accepted
htaccess file to perform specific rules to different domains
You seem to be behind an SSL proxy(?), hence the use of the X-Forwarded-Proto request header, instead of the HTTPS server variable.
RewriteCond %{REQUEST_URI} !(health_check\.php)$
RewriteCond %{...
- 12.1k
1
vote
Redirect all the traffic from multiple domains to single domain using htaccess
Adding the below apache rewrite rules should do the trick for you.
RewriteEngine On
RewriteBase /
# first redirect
RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/...
- 264
1
vote
Rewrite cond for domain and www.domain letsencrypt
Let's take a look at this line:
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Here, the %{SERVER_NAME} variable depends on the UseCanonicalName, by default set Off. ...
- 44.8k
1
vote
Accepted
rewrite / restrict specific domain name in apache
You can do this using mod_rewrite which allows you to check the host through which the site is being accessed. Try the following, in your server config (or <Directory> section or .htaccess file):...
- 12.1k
1
vote
to set RequestHeader in apache httpd server is not working
In your original configuration you are using Header instead of RequestHeader. Header sets a response header not a request header.
I've tested it by adding the logging of the X-header HTTP header to ...
- 2,326
1
vote
Accepted
Have Apache serve static content instead of forwarding it to Plone (++resource++)
I found a way to make it work.
After increasing the log level:
LogLevel alert rewrite:trace5
... I got some additional info about the matching of patterns (at level 4).
When put in square brackets,...
- 165
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
rewritecond × 130mod-rewrite × 75
rewrite × 56
.htaccess × 55
apache-2.2 × 45
apache-2.4 × 22
redirect × 10
nginx × 7
apache2 × 7
virtualhost × 5
301-redirect × 5
url × 3
web-server × 2
ssl-certificate × 2
domain × 2
https × 2
httpd × 2
mod-proxy × 2
regex × 2
httpd.conf × 2
http-status-code-404 × 2
linux × 1
ubuntu × 1
php × 1
debian × 1