All Questions
Tagged with apache-2.4 mod-rewrite
416
questions
0
votes
1
answer
151
views
Use ProxyPass only if remote address is in subnet
I have a php application running with a mostly default config that lives in var/www/html/app:
<VirtualHost *:443>
ServerName myhost.com
DocumentRoot /var/www/html
<Directory "...
0
votes
0
answers
27
views
In what order does Apache evaluate `RedirectRule` when provided by virtual host, directory context and .htaccess?
I have several RewriteRule inside <VirtualHost>, inside the <Directory> directive which belongs to the web root of said <VirtualHost> and inside .htaccess of that directory.
Question:...
0
votes
3
answers
95
views
Apache redirect http://%{HTTP_HOST}:%{SERVER_PORT}/%{REQUEST_URI} to https://%{HTTP_HOST}%{REQUEST_URI}
I am attempting to redirect
<VirtualHost *:5555>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} =5555
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=...
-3
votes
0
answers
53
views
https domain is not redirecting properly
My website can be referred to as example.co.uk and example.net with optional www at the front.
I am trying to set up Apache 2.4 so that if anyone lands on anything it always permanently redirects to ...
0
votes
1
answer
49
views
Apache rewrite any uri to index.html but existing files
My front-end project is based on 1 file: frontend/index.html
It means that every request like /contact, /about, etc should be responded by index.html file.
I was thought I can use these lines in my ...
1
vote
1
answer
45
views
apache mod-rewrite backreference won't match
I'm trying to test if the value of HTTP_HOST exists as part of the URI.
First, I capture the value into a backreference with:
RewriteCond "%{HTTP_HOST}" "(.+)"
Then I test for ...
0
votes
0
answers
36
views
Why Apache SPA mod_rewrite config uses dot in regex and caret crashes Apache?
Typical Apache SPA config based on mod_rewrite:
DocumentRoot "${webDir}"
<Directory "${webDir}">
LogLevel rewrite:trace8
RewriteEngine On
RewriteCond %{...
1
vote
1
answer
50
views
Apache AliasMatch with Multiple Subdomains
I have the following virtual hosts:
<VirtualHost *:443>
ServerName article.example.com
AliasMatch "^/(.*)" "/var/www/html/article.php"
</VirtualHost>
<...
0
votes
1
answer
114
views
Apache - Is it possible to rewrite urls based on fragments (hashtag)?
Using Apache/2.4.54 (Win64)
I have been requested to rewrite from old domain to new like this
From https://oldtest.mydomain.com/company/customerpage/#/customer/<getThisNumber>/something
To ...
1
vote
1
answer
93
views
How to make multiple changes to REQUEST_URI at once?
I'm dealing with requests from a proprietary client, that sometimes uses back- rather than forward-slashes: GET /path\to\the\file.txt, and I'd like to straighten them all out.
mod_rewrite can replace ...
2
votes
1
answer
100
views
How to change HTTP-status based on origin's header?
I'm dealing with a proprietary HTTP-server, which always responds with code 200 -- even when an error occurred. The indication of an error, if any, can only be found in the custom header, for example: ...
2
votes
1
answer
211
views
Rewrite Apache Condition not preventing rewrite from getting applied
I'm trying to only allow incoming requests to /multi if the Content-Type request header starts with multipart/form-data, while requests to other POST, PUT, or DELETE endpoints must always have the ...
0
votes
1
answer
315
views
getting error Content Encoding Error (ERR_CONTENT_DECODING_FAILED) with Apache served pre-compressed .br (Brotli) files
How can I get Apache to serve pre-compresses Brotli files?
With Chrome I am getting
net::ERR_CONTENT_DECODING_FAILED 200
I made my pre-compressed .br (Brotli) files from minimized .html files (.min....
0
votes
1
answer
57
views
Apache AliasMatch with Wildcard Not Working As Intended
I am trying map all wildcards for a directory /a/* onto on file article.php using AliasMatch ^/a/(.*) /article.php but without redirecting (I want to keep the url looking the same). But I am getting a ...
0
votes
1
answer
288
views
htaccess file with RewriteEngine On causes a 403
Windows Server 2022
Apache 2.4.57 x64
httpd.conf - relevant
<Directory />
Options none
AllowOverride none
Require all denied
</Directory>
DirectoryIndex index.html
<Files &...
0
votes
0
answers
24
views
Why is adding this line to my mod_rewrite creates looping issue, and how to avoid it?
I pasted below the existing mod_rewrite section of the .htaccess of my Magento site.
I need to modify it to implement a short URL scheme that would redirect all requests like mysite.com/-jk7ASD63 (all ...
0
votes
1
answer
69
views
Apache how to find cause of 404 with rewriterule ignored
So I have this
RewriteCond %{REQUEST_URI} (da-dk)/(.*)(/|\.php)$
RewriteRule ^(da-dk)/(.*)(/|\.php)$ /$2$3 [L]
But for some reasons example.com/da-dk/ gives "404 - not found"
I would like ...
0
votes
0
answers
132
views
How to use Apache's mod_rewrite to change the HTTP version in a request?
I have an old system sending a POST to an old version of Apache(2.4.9) that is not sending the HTTP version. The old system has no issue but I want to update Apache to the latest. When I do, Apache ...
1
vote
1
answer
160
views
Apache 2.4 expr - how to load a html file via RewriteRule?
On Apache 2.4, Having a bunch of mixed SEO friendly and dynamic URLs on an ecom site I want to implement a simple caching system for my blog posts and product pages. First I want to have md5(...
1
vote
1
answer
282
views
mod_rewrite rules on subdirectory not woring due to parent rules
My application lives in one directory and is served from a public folder, and I have an API endpoint in a sub-directory of public, both of which are redirected to their own respective index.php files. ...
0
votes
0
answers
55
views
Apache RewriteCond/RewriteRule with variables causes infinite redirects
I'm trying to use variables in the RewriteCond and RewriteRule like so:
SetEnv DOMAIN "example.com"
SetEnv SUBDOMAINS "www|assets"
#more config stuff, unrelated
#I separated the ...
0
votes
0
answers
129
views
Serve mixed case files case-insensitive on Linux Apache without mod_speling?
On my media subdomain (nice separation of concerns, also for rulesets)
I have files which are in Mixed-Case-intentionally (for maximum semantics, also for downloads)
which I want to serve case-...
0
votes
0
answers
31
views
Apache RewriteRule losing one slash of the https://
On my apache server, I need to pass full URLs as parameters to a php function. However, when I use something like:
RewriteRule ^(.*)$ ../image.php?url=$1
$1 ends up losing one of the slashes of the ...
0
votes
1
answer
93
views
Redirect rules for multiple enviroments
I have written a set of rules for 3 different environments on the same server. In a nutshell I would redirect the users to the Dev, Stage and Prod single sites. Also enforce https and www for the ...
1
vote
0
answers
119
views
Apache 2.4 "client denied by server configuration" caused by Require expr - even though the request succeeds
Our apache error log is littered with messages saying client denied by server configuration, even though the htaccess configuration is working as intended.
Here is the relevant bit of the htaccess:
...
1
vote
1
answer
56
views
Apache ToLower on all Wordpress pages (not PDF/CSS/JS)
I'm having issues performing a 301 redirection of URLs that contain capitals to lowercase, excluding static files (PDF/CSS/JS/JPEG/JPG/PNG/WEBP...etc). For example:
https://www.example.com/Page/ would ...
1
vote
1
answer
390
views
Apache htaccess ruleset: Try request as: 1) file as-is 2) file + .html suffix 3) DirectoryIndex 4) Else to index.php CMS router
I'd like to express this ruleset
If the request is /hello then try the following in the given order:
/hello — File of that name exists (file without file extension).
Edit: Not a necessity. Only a ...
0
votes
1
answer
219
views
Ban by IP and auto redirect to HTTPS
I'm trying to block access to the website for certain IP addresses. For this I have a file ipblacklist.conf with list of IPs in the following format one line per IP:
Require not ip xxx.xxx.xxx.xxx
...
1
vote
1
answer
425
views
Apache mod_rewrite RewriteRule loops despite L flag
Apache/2.4.54.
I am trying to achieve that similar URLs (e.g. "/anystuff.htm") are externally redirected to "/something" which internally is "something.html".
But the ...
2
votes
1
answer
7k
views
Can't get Apache rewrite to work on Docker PHP-Apache container
I've followed suit to quite some instructions, tutorials, and also questions in this forum, but I can still not get this working. I've setup a REST API using a PHP Apache Docker container, and need to ...
0
votes
0
answers
683
views
Want to redirect URL and change slug to url parameter
I am stuck with a mod rewriting on Apache htaccess.
my URL looks like this :
http://localhost/Ac5GRnXW
I want it to redirect like this:
http://localhost/redirect.php?id=Ac5GRnXW
I am using the ...
1
vote
1
answer
85
views
htaccess syntax issue when moving script to a subfolder
I have recently purchased a script but this script only works in public_html folder . I need to install it in a subfolder named shop ( public_html/shop/ ) . Now the following .htaccess rules work ...
1
vote
1
answer
3k
views
htaccess, block access a url with parameters
If I want to block access to example.com/path/?xxxx (xxxx is variable), but allow access to example.com/path/, how should I write it in my .htaccess?
0
votes
1
answer
1k
views
Apache mod_rewrite will not redirect from root folder to subfolder
I will preface this question by saying that I know next to nothing about Apache directives, but I need to use them in my project to hide the contents of the root folder, and also to hide the /public ...
3
votes
1
answer
216
views
Apache2 mod rewrite extremely slow, on one server only
I have a site on my local ubuntu dev box with some mod rewrite rules, which we are attempting to use to force google and other bots to index the correct page, rather than our ajax snippets as they ...
0
votes
0
answers
39
views
apache mod_rewrite path to querystring - keep base directory
I try to "beautify" my URLs from eg. www.example.com/page.php&id=3 to www.example.com/page/3
I can achieve this with:
RewriteEngine On
RewriteRule ^(page)/([0-9]+)$ page.php?id=$2
The ...
1
vote
0
answers
56
views
Rewrite rules for all but one directory (recursive)
We need to do a rewrite for a subdirectory of a site to its own host, with the exception of one directory. We also need to be sure that the original subdirectory is dropped in the rewrite. (using ...
0
votes
0
answers
270
views
reverse proxy Apache that redirects filtering by ip and path
I am trying to create a reverse proxy with apache that if it receives a request with /thisismypath as path and the ip address that make that request is 192.168.2.12 the it should redirect to 192.168.1....
1
vote
1
answer
140
views
RewriteCond for APIKEY
I am trying to create a RewriteRule which looks at the incoming Header for an APIKey and if it contains a matching string then it will redirect to respective URL else, it should be inaccessible.
I am ...
1
vote
1
answer
208
views
On Apache how to switch off DirectorySlash only for requests to a specific subdomain?
Served by Apache I'd like on one subdomain site of mine (say sub.mydomain.com) that URLs without trailing slashes point directly (without external redirect) to the index file in the underlying folder. ...
1
vote
1
answer
172
views
Forbidden on everything except for scripts located on subfolders
I want to forbid everything coming on a specific domain (e.g. example.com) except for some entry points (here, PHP files) located on a specific path (e.g. example.com/subfolder1/subfolder2/script.php)....
1
vote
1
answer
164
views
Consolidating many VirtualHosts into one block, is this a job for SetEnvIf?
Edit I think what I need here is SetEnvIf
I'm attempting to consolidate all of my port-80 VirtualHosts into one block for convenience, but I'm struggling with the final piece of the puzzle.
All port ...
1
vote
0
answers
1k
views
Apache reverse proxy to site using NTLM authentication fails with mod_rewrite but not mod_proxy
We have a reverse proxy server in front of an Exchange server and would like to lock down more of the paths. Minimized examples:
Fails (but works for all pages that don't require authentication):
<...
1
vote
3
answers
439
views
Hide path in URL of Rocket.Chat with mod_rewrite
I have been looking for a solution to my problem for days. Unfortunately without success.
Before I try now days further around and it in the end no solution I ask you.
On my Univention server I have ...
1
vote
1
answer
2k
views
Apache 500 Error when proxying api subdirectory
I am trying to redirect PUT request for a specific endpoint to another host.
The said endpoint resides under /internal and accepts only PUT requests.
The other endpoints under /internal will continue ...
0
votes
1
answer
395
views
Redirect works, pass-through does not
Our CMS has a handler named root, which works: http://example.com/root serves, what we want it to serve.
We'd like requests for "naked" domain (http://example.com) to be handled by that same ...
0
votes
0
answers
160
views
Language based RewriteRule like mysite.com/en/ in .htaccess
I'm trying to write redirect directives in the .htaccess to forward internally all user requests like this:
Every request in a language folder should redirect to the requested file with the language ...
1
vote
1
answer
698
views
Is it possible to detect an ajax request with Apache 2.4 for a mod_rewrite rule?
Is it possible?
Trying to move my script security to the server-level.
With PHP, just check if $_SERVER['HTTP_X_REQUESTED_WITH'] is set to XMLHttpRequest (jQuery added).
I guess maybe a better ...
1
vote
0
answers
712
views
Apache Reverse Proxy rewrite rule for complex URL. "Too Many Redirects" error
I am trying to configure a reverse proxy to my backend server.
This is my previous configuration which is working.
Define REMOTE_ADDR proxyserver.domain.com
<VirtualHost *:443>
...
0
votes
0
answers
113
views
Hide your paths/filenames in apache
in Apache 2.4, can I hide all "paths" from the browsers?
if somebody are on https://example.com/users/list.html it would only say https://example.com in the addressbar, and if someone takes ...