Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [mod-rewrite]

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs.

Filter by
Sorted by
Tagged with
0 votes
0 answers
43 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 ...
Sean Kendle's user avatar
3 votes
1 answer
321 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 ...
klewis's user avatar
  • 133
0 votes
1 answer
35 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 ...
user1311554's user avatar
1 vote
1 answer
137 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 ...
KBM's user avatar
  • 13
0 votes
1 answer
102 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/...
Andrew's user avatar
  • 113
1 vote
2 answers
368 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....
Mario's user avatar
  • 11
0 votes
0 answers
71 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. ...
andynewman's user avatar
0 votes
1 answer
49 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 ...
nulll's user avatar
  • 517
0 votes
0 answers
199 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 ...
user8373873's user avatar
0 votes
0 answers
150 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....
Lethal's user avatar
  • 1
0 votes
1 answer
180 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 "...
GammaGames's user avatar
0 votes
0 answers
62 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:...
user2690527's user avatar
0 votes
0 answers
52 views

htaccess LimitInternalRecursion error

my htaccess <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On RewriteBase / # Handle ...
Hicham 's user avatar
0 votes
3 answers
346 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=...
sroth79's user avatar
0 votes
1 answer
48 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 ...
Prajwal 's user avatar
1 vote
1 answer
77 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....
Josh Hawkes's user avatar
0 votes
1 answer
101 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 ...
MHSarmadi's user avatar
1 vote
1 answer
87 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 ...
flymike's user avatar
  • 233
0 votes
0 answers
77 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 ...
Anpang's user avatar
  • 1
0 votes
0 answers
58 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 %{...
gavenkoa's user avatar
  • 912
2 votes
1 answer
735 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 ^(....
alancc's user avatar
  • 183
0 votes
1 answer
438 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 %{...
Frank Eno's user avatar
  • 101
1 vote
1 answer
103 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> <...
Maciek's user avatar
  • 139
0 votes
1 answer
281 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 ...
rhellem's user avatar
  • 305
0 votes
1 answer
38 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 ...
Rene Veerman's user avatar
1 vote
1 answer
125 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 ...
Mikhail T.'s user avatar
  • 2,401
2 votes
1 answer
221 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: ...
Mikhail T.'s user avatar
  • 2,401
2 votes
1 answer
403 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 ...
DevelJoe's user avatar
  • 197
0 votes
2 answers
698 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....
MeSo2's user avatar
  • 274
1 vote
1 answer
622 views

htaccess redirects with special characters on an specific url not working

I need some help creating a redirect, I'm trying to replace all - to +, but both are special characters and also want to do it only when the URL contains ?s=. This is an example example.com/?s=i-need-...
Michel Zúñiga's user avatar
1 vote
1 answer
155 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 ...
Life after Guest's user avatar
0 votes
1 answer
136 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 ...
Maciek's user avatar
  • 139
2 votes
1 answer
349 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 ...
traxx2012's user avatar
  • 123
1 vote
1 answer
803 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 &...
MonkeyZeus's user avatar
0 votes
0 answers
41 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 ...
John Doisneau's user avatar
0 votes
1 answer
107 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 ...
Tom's user avatar
  • 97
1 vote
0 answers
158 views

Apache Rewrite Based on Query String

I'm trying to detect the presence of a particular name/value pair in the query string and, if it exists, do a thing. I'm trying to do this in a conf file that's stored in conf-available/ and after ...
Rob Wilkerson's user avatar
2 votes
3 answers
1k views

Apache on debian don't redirect http to https correctly

Debian 11 config file: /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} ...
Ishayahu's user avatar
  • 187
0 votes
1 answer
86 views

How to add apache server config rewrite rule for encoding pipe symbol in url

I am getting a 404 error on URL that contains pipe symbol. If I encode manually with %7C for pipe it works properly. I want to add a rule in Apache conf file that automatically replaces pipe character ...
dl_coder8's user avatar
1 vote
1 answer
136 views

rewrite based on script in URL

Using Apache 2.2.x -- my usual approach to blocking script kiddies from looking for various scripts on the server is to use dynamically created 'deny from' lists with the offending ip's. Works, but is ...
Johnny Canuck's user avatar
0 votes
0 answers
245 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 ...
Scott Kirkpatrick's user avatar
1 vote
1 answer
260 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(...
nikis's user avatar
  • 11
1 vote
1 answer
289 views

How to replace custom url old domain to new domain with .htaccess

How to replace all url entire website with new domain and new permalink? I have 5k url to replace at my site. Example : Current URL: oldomain.com/2020/12/data-raid-4963.html Replace To: sub.newdomain....
Maone van Cobain's user avatar
0 votes
0 answers
33 views

How to write parameter URL in .htacess Rewrite

I want to point this URL in .htaccess: http://www.example.com/furniture/chair/foldingchair to http://www.example.com/products.asp?catID=1&SubID=2&SubCatID=3 where catID=1 = furniture SubID=...
Khan101's user avatar
1 vote
1 answer
380 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. ...
oucil's user avatar
  • 598
0 votes
0 answers
976 views

Apache 2.4.52 HTTPS Rewrite no longer works on Ubuntu 22.04

I have been forcing HTTPS upgrade through mod_rewrite for years on Ubuntu 18.04 LTS servers. I recently upgraded a few of these servers to Ubuntu 22.04.1 LTS to ensure the latest security and Apache ...
Nick Bedford's user avatar
0 votes
0 answers
191 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-...
porg's user avatar
  • 163
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 ...
user59067's user avatar
  • 215
0 votes
1 answer
104 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 ...
Manoxs's user avatar
  • 1
1 vote
0 answers
150 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: ...
Jonathan's user avatar
  • 111

1
2 3 4 5
45