Questions tagged [mod-rewrite]
mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs.
2,250 questions
0 votes
0 answers
114 views
Setup Mojolicious app transparently via CGI with Apache mod_rewrite
I am developing a Mojolicious web application and want to deploy it to shared web hosting which offers Apache with CGI and Perl including Mojolicious. How to configure it via .htaccess? https://myapp....
4 votes
2 answers
591 views
Why Apache Alias directive doesn't have precedence to Rewrite?
I need to have a rewrite of http to https with Apache and I also need to handle let's encrypt challenge for renewal, then I wrote this configuration, with Alias for Let's Encrypt and Rewrite for http-&...
8 votes
3 answers
834 views
Why RewriteRule behaves different if request URL has a trailing slash and when not?
My intention is to serve a website from a subfolder without changing the document root to point at that folder (since I cannot because it is on a shared hosting). For this purpose I added this to my ....
1 vote
1 answer
95 views
Apache redirect http to https except localhost
I know that there are several similar questions, but after many tests I am not able to get what I want. First of all, I read that apache can redirect in three ways: redirect, mod_rewrite or with if-...
0 votes
1 answer
99 views
htaccess - How to leave only 1st URL parameter and remove the rest parameters if there are any
Google is crawling somewhere my URLs with some non-existing garbage URL parameters at the end of canonical URLs. So, how to leave only 1st URL parameter and remove the rest parameters if there are any ...
1 vote
3 answers
331 views
Changing URL structures via htaccess
sorry; have not done this since 2016, and kinda stumped. Need help with likely simple mod_rewrite rule for htaccess file to redirect old files which no longer have a trailing _number on the end. Need ...
0 votes
0 answers
143 views
Apache2 configuring Duplicati behind proxy
Duplicati for any reason will fail if you try to proxy the root folder so the domain to main IP as it had been discussed here: https://github.com/duplicati/duplicati/issues/1932 The only solution is ...
1 vote
1 answer
180 views
RewriteRule to Access Files Outside of Document Root
How do I write a RewriteRule that will access files outside of the document root? We are running multiple sites on multiple subdomains using a shared hosting service. There are a number of core files ...
2 votes
1 answer
149 views
Serve static files and proxy if not found
I'm trying to configure a vhost to work with a proxy, but only if the request is not for a static file -- in which case I'd like Apache to serve it. Here's what I'm using: <VirtualHost *:80> ...
0 votes
1 answer
121 views
Apache2 RewriteRule does nothing
I have a mediawiki installation on Ubuntu and am trying to redirect the the domain from the Apache "It Works!" page to the main page of the wiki. My apache2.conf contains the following: <...
0 votes
0 answers
75 views
Apache rewrite rule ignoring everything after / for one rule
I am running a webserver behind a Cloudflare load balancer and a redirect I have set up in Apache isn't working. I have two https ports running on the server, 443 and 8443. Most traffic is for the 443 ...
0 votes
1 answer
79 views
htaccess is rewriting all subsequent urls to same page
My htaccess is correctly implementing for the the first file i write. But for subsequent files it is redirecting every other redirect to same page. The article rewrites are working fine but other ...
0 votes
1 answer
110 views
Regex not working in apache rewritecond
Given the url: https://{SITE}/tgif/flink?search1=scode=atrre%20and%20year=2023&format=USGARS I want to rewrite it to https://{SITE}/tgif/flink/TERO/2023. Where 2023 is the only variable part of ...
-1 votes
1 answer
343 views
Test a website without changing DNS settings
I need to test a website before changing DNS records. There are tools such as Skipdns.link and in the past hostcx. I need this but without the limitation of skipdns.link. For example all URLs of ...
4 votes
1 answer
183 views
Case insensitivity for Cyrillic characters in Apache .htaccess RegEx does not work
Consider the following RewriteRules: RewriteEngline On RewriteRule ^services$ services.php RewriteRule ^новости$ news.php What they achieve is that www.example.com/services loads the content of ...
3 votes
1 answer
1k views
How to match beginning of file name using htaccess
I am attempting to modifying my .htaccess file within a specific directory. If a web user attempts to find any file in this directory that may be named like the following options, I want them to be ...
0 votes
1 answer
119 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 ...
1 vote
1 answer
998 views
Creating a .htaccess in a subdirectory causes rewrite rules in higher level .htaccess to stop working
Sorry if this has been asked/answered before, but I was not able to find an answer to this particular problem. If I create a .htaccess file with a simple rewrite rule, that rule works. If I create ...
0 votes
1 answer
214 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/...
1 vote
2 answers
2k views
Apache Rewrite Engine redirect all request to index.php
I have a PHP web application on a Apache Web Server. The path to to web application on the Server is: /var/www/html/intern/organisation/example_app The URL to the web application is: https://www....
0 votes
0 answers
104 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
112 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
0 answers
463 views
Intercept HTTP POST response from Reverse Proxy in Apache
I have following configuration in my Apache server and requirement is to intercept HTTP POST request to /api/submit endpoint and trigger a CURL request to a remote URL before forwarding it to backend ...
0 votes
0 answers
162 views
Apache2 folders redirect to IPs
I have installed Apache/2.4.56 (Debian), a noip URL and severals LXC containers. I need to access to the web apps inside the LXC containers: example.com/app1 -> LXC container 1 (with Zend2) example....
0 votes
1 answer
239 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
189 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
0 answers
170 views
htaccess LimitInternalRecursion error
my htaccess <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On RewriteBase / # Handle ...
0 votes
3 answers
1k 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
83 views
Can someone help me out in lighttpd server facing issue in mod rewrite and 404 error in cms
I am beginner in lighttpd I am facing problem in cms script because of htaccess as htaccess dont work in lighttpd I had enabled mod_rewrite in lighttpd.conf file and due to this I am facing 404 error ...
1 vote
1 answer
105 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....
0 votes
1 answer
173 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
198 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
159 views
Rewrite files up a directory and remove file extension
I need to rewrite files up a directory and remove the file extension I have something like https://example.com/dir/file.svg and I want to rewrite the URL to https://example.com/file Here's my ...
0 votes
0 answers
94 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 %{...
2 votes
1 answer
2k views
How to disable .htaccess redirect for a specific folder
I write the following .htaccess rules to redirect all URLs from www.a.com to www.b.com: RewriteEngine on RewriteCond %{http_host} ^www.a.com [NC,OR] RewriteCond %{http_host} ^a.com [NC] RewriteRule ^(....
0 votes
1 answer
665 views
htaccess rewrite rule to a specific PHP page doesn't work
I have the following code in my .htaccess file, placed in the root of my Ubuntu 22.04 instance: Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...
1 vote
1 answer
216 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
694 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 ...
0 votes
1 answer
49 views
apache2 mod_rewrite rule error (although i think i did everything correctly, and have exhausted google's searchresults)
this rewrite rule is not hitting it's mark :( RewriteCond %{REQUEST_METHOD} ^(GET)$ RewriteRule ^/wiki-search/(.+)$ NicerAppWebOS/index.php?app-wikipedia.org-search=$1 [L,END,PT,DPI] apache ...
1 vote
1 answer
195 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
547 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
914 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
1k 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....
2 votes
1 answer
1k views
'htaccess' redirects with special characters in a specific URL is not working
I need some help creating a redirect. I'm trying to replace all - to +, but both are special characters, and I also want to do it only when the URL contains ?s=. This is an example: example.com/?s=i-...
1 vote
1 answer
397 views
Edit .htaccess file to make file accessible
I was trying to make a WordPress plugin work, when I found, after hours of debugging, trial, errors and praying ancient Greek gods, that the plugin did not work because it was impossible for the ...
0 votes
1 answer
360 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 ...
2 votes
1 answer
556 views
.htaccess return error if no RewriteRule meets the request
I'm trying my hands on writing a simple REST API and am currently trying to properly configure my .htaccess file. What I'd like to achieve is the following: have RewriteRules to direct requests ...
1 vote
1 answer
2k 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
103 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
251 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 ...