All Questions
Tagged with apache-2.4 mod-rewrite
419
questions
0
votes
0
answers
48
views
Using environment variables and a redirect loop to force-clear a 301 redirect
We mistakenly used a 301 redirect on a very important page, and now that we want to actually use the page, many users' browsers have the 301 stuck in their cache. The problem is that the destination ...
0
votes
1
answer
37
views
apache redirect/rewrite http to https with many virtualhosts
I have an apache webserver that has about 150 VirtualHosts spread out over 9 IP addresses. I'd like to redirect or rewrite http connections to https. The solutions I've found have the rewrite/redirect ...
0
votes
1
answer
109
views
Rewrite urls only for certain folder and remove parts of the url in Apache
I have an old project in PHP which I'm trying to modernize. The routing of the old project is just files on the server which you'd access via the url.
So for example a file placed in folder/subfolder/...
0
votes
0
answers
73
views
Apache custom rewrite rule, using code
I would like to have Apache handle some custom URL rewrite code that I have. This code rewrites the following urls:
https://www.example.com/request?data=SOMEDATABLOB
into urls pointing to PHP pages. ...
0
votes
1
answer
51
views
Content negotiation, send webp request to Symfony when webp file does not exist
On Apache Httpd 2.4, I know that from a .htaccess file I can do this
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
RewriteRule (.+)\.jpg$ $1.webp [T=image/webp]
in ...
0
votes
1
answer
182
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
76
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
426
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=...
0
votes
1
answer
107
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
99
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
61
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
117
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
321
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
130
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
254
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
442
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
2
answers
760
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
161
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 ...
1
vote
1
answer
892
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
44
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
112
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
256
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
273
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
392
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
197
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
34
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
110
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
151
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
83
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
497
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
288
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
549
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 ...
3
votes
1
answer
10k
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
881
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
102
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
4k
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
316
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
58
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
81
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
307
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
180
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
299
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
222
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
179
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
479
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
507
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
164
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 ...