Skip to main content

Questions tagged [rewritecond]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
82 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
1 vote
1 answer
104 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
85 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
1 answer
495 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
0 votes
1 answer
342 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
  • 315
1 vote
0 answers
170 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
0 votes
1 answer
411 views

ErrorDocument not working for any error. Ubuntu Apache

I'm having an issue with getting the ErrorDocument to work. I have tried most of the suggestions on most of the forms and posts. The only thing I know that I have that the others did not is the ...
La Phyzz's user avatar
0 votes
1 answer
319 views

Is it possible to access a modified query string in a RewriteCond *after* applying a RewriteRule?

Is it possible to access a modified query string in a RewriteCond after applying a RewriteRule? What I'm trying is to apply ... RewriteCond %{QUERY_STRING} ^(.*)&?id=([^&]+)&?(.*)$ [NC] ...
user27772's user avatar
  • 111
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 ...
user13947255's user avatar
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 ...
denoise's user avatar
  • 53
1 vote
1 answer
184 views

Apache http to https WITHOUT any adress?

a normal http to https rewrite could look like this: RewriteEngine On # RewriteCond %{HTTP_HOST} !^example.com$ # RewriteRule /.* https://example.com/ [R] but this code specifies the site to "...
Adam Larsson's user avatar
1 vote
1 answer
382 views

htaccess rewrite rule not working with file extentions

I have two domains setup on the same folder on a server. i.e. dl.d123.com @ /var/www/public_html/dl.domain123.com dl.domain123.com @ /var/www/public_html/dl.domain123.com I have an htaccess file ...
iraqiboy90's user avatar
1 vote
1 answer
3k views

Should I escape slash '/' in RewriteCond?

Whether I need to escape the slash '/' in RewriteCond? Currently I write the following rule in .htaccess: RewriteCond %{QUERY_STRING} rp=/knowledgebase/ RewriteRule ^index\.php$ https://www.datanumen....
alancc's user avatar
  • 183
1 vote
1 answer
403 views

Rewriterule not working with Joomla urls due to question mark and other special characters, also due to long urls

So I moved from Joomla CMS and now I need to finish my permanent redirects, but the following redirect isn't working (it's actually returning an error 404): RewriteCond %{HOST_NAME} =&?$ #...
Brave Warrior's user avatar
0 votes
0 answers
339 views

Exclusion in Rewrite Rule

I have a rule in .htaccess redirecting all HTTP requests to HTTPS. I need to exclude two specific paths because they are called by a legacy application to download a file, connecting using TLS 1.0 (...
RadioLontra's user avatar
2 votes
1 answer
622 views

Apache: Don't log errors for certain non-existing files (regular file or symbolic link)

I want to prevent Apache from logging "File does not exist" errors for certain irrelevant non-existing files that are often requested, such as "apple-touch-icon-120x120.png". These ...
David Scherfgen's user avatar
1 vote
1 answer
715 views

Validate QUERY_STRING on RewriteCond for XSS protection

I would like to create a rewrite condition which validate the QUERY_STRING to prevent from XSS. My item look like: /ItemPage.jsp?itemId=item_12345_12 where item_12345 is required and "_{...
B3nny's user avatar
  • 13
2 votes
1 answer
926 views

RewriteMap inside RewriteCond doesn't work (Apache)

I have a RewriteCond that checks if {QUERY_STRING} contains the right version number, if it doesn't then redirect users to the correct version. For instance if v0.7 is the latest, users accessing http:...
James Wong's user avatar
0 votes
1 answer
440 views

Configuring www.domain.com and domain.com with zonefile or letsencrypt to always forward to domain.com

I have a example that should always result in https://example.com, even when the user is entering www.example.com, https or not. Ideally, the automated letsencrypt config https config file should work....
uncovery's user avatar
  • 365
0 votes
1 answer
126 views

apache .htaccess redirecting on one link, but not the other

I have this .htaccess file (this was the one that came with laravel. The only changes I made were to force https in the URL and the code shown below: <IfModule mod_rewrite.c> <IfModule ...
stprysmqpwcuddakue's user avatar
2 votes
1 answer
1k views

Nginx: After removing .html suffixes, how to redirect all requests to the new URLs?

I want to optimize the link structure of an older Magento shop system. Until now, when generating the static pages, a .html suffix was added to the corresponding path. Due to an earlier problem, paths ...
max stern's user avatar
0 votes
1 answer
56 views

Server Rewrites No Longer Works

I have been using the server commands below in my .htaccess file for months without any problems, but yesterday, out-of-the-blue, whenever I attempted to navigate from the website homepage to other ...
Krang's user avatar
  • 1
1 vote
1 answer
1k views

Conditional String Htaccess

I need to validate that an environment variable exists and that the value is equal to "cloudflare", in case there is no deny access. I have done multiple tests, and I have not been able to make it ...
SolucionTi's user avatar
0 votes
1 answer
2k views

htaccess - .htaccess in sub directory not inheriting .htaccess in root directory

i have 2 .htaccess files first in /public_html/ #ErrorDocument 404 https://example.com/en/404.php RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://example.com/$1 [R,L] ...
Amr Ahmed's user avatar
1 vote
1 answer
666 views

htaccess rewrite country without subdomains

i need to rewrite URL from us.example.com to example.com?country=us without subdomains I tried these 2 rules: 1. RewriteRule (US|EG) ?c=$1 [NC , L] 2. RewriteRule :\/\/(.*?).example.com ?C=$...
Amr Ahmed's user avatar
1 vote
1 answer
804 views

Apache doesn't match rewritten URL as regular file

I've setup a .htaccess to redirect requests against the containing directory /htdocs/foo to the file bar.php. 1st of all: I know how to achieve this in general, but for reasons out of my control the ....
Thorsten's user avatar
0 votes
0 answers
130 views

Apache mod_rewrite order not working as expected

I want to respond with 404 for /autodiscover/ on https://mycompany.com as this is the URL Outlook (and other clients using Exchange autodiscover) checks at startup. What this vHost also does is ...
koffik's user avatar
  • 1
3 votes
2 answers
7k views

Explanation of new line in htaccess file: RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?

Recently I noticed that a new line was added in the htaccess file in several locations throughout the file. RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)? I don't ...
Kenneth Poveda Mata's user avatar
1 vote
1 answer
749 views

Apache RewriteEngine config purpose

I ran into this snippet in an Apache config file that someone else wrote, but I'm not sure of the purpose. Could anyone explain what this is for? RewriteEngine On RewriteCond %{THE_REQUEST} !HTTP/1\....
FluffyBeing's user avatar
2 votes
1 answer
22k views

Nginx location match if not equal

I have www.example.com/test and i want to write a condition if requested url is not equal to /test do a rewrite or redirect to www.example.com. The closest i can get is a code below but when i want to ...
justdoole's user avatar
3 votes
3 answers
244 views

Updated SSL certs and now rewrite conditions no longer working for apache2

I'm running an Ubuntu 14.04 server with Apache2 v2.4.7. Recently our site was getting errors from Chrome saying we needed to update our certs. I just completed that earlier this week, updating the ...
risa_risa's user avatar
  • 131
1 vote
1 answer
7k views

Why are Apache Rewrite Conditions not working?

I tried to perform a redirect writing in .htaccess file: RewriteEngine on RewriteRule article-1 www.another-site.com/article-1 [R=301,L,NC] and it works correctly. Anyway, when I add a rewrite ...
Arthu83's user avatar
  • 11
1 vote
1 answer
3k views

Apache Redirect to /index.php - How to handle direct requests for /index.php

I'm not 100% sure if this should be on server fault or stack overflow, though I'm leaning towards server fault. Most PHP frameworks utilize Apache redirects to funnel all request to /index.php and ...
d.lanza38's user avatar
  • 387
1 vote
1 answer
366 views

Conditional http redirect to https depending on site URL? (Apache)

I have a url that is used to store data across multiple sites based on client ID. Many of our clients are now wanting to use secure https resolution, yet the data referenced on their sites from this ...
David W.'s user avatar
2 votes
0 answers
296 views

Multiple rewritecond with different variables

I am trying to match on two different things in a single request to proxy a request to a different server. My rewrite conditions are: RewriteCond %{QUERY_STRING} (token=.*)$ RewriteCond %{...
hacktek's user avatar
  • 21
2 votes
1 answer
5k views

GeoIP: Redirect all but specific countries

I am using Apache's GeoIP module and a MaxMind database to determine the country of a visitor based on their IP address and redirecting them to a country sub-folder as shown below: RewriteCond %{ENV:...
Ralph's user avatar
  • 902
1 vote
1 answer
1k views

htaccess file to perform specific rules to different domains [duplicate]

I have one application with is server over a number of domains (each customizes the appearance of the application. In addition, there is a common domain which has multiple subdomains to display the ...
Tom's user avatar
  • 133
2 votes
1 answer
2k views

Why HTACCESS RewriteCond %{HTTP_COOKIE} only for php and not working for html?

I was trying to redirect all direct access in my subfolder using this code RewriteEngine on RewriteCond %{HTTP_COOKIE} !user_cookie=[^;] RewriteRule .* http://webhost.org/ [R=301,L] I realise it ...
MyFault's user avatar
  • 21
3 votes
1 answer
1k views

Apache rewrite to extract multiple pieces of data from original request URL

Trying to create an Apache rewrite that applies to video files only, over to a dedicated video-serving web-server. It requires rewrite logic that extracts multiple pieces of information from the ...
K.McCallum's user avatar
2 votes
0 answers
452 views

Rewrite rule loses query parameters

I have a webserver running apache2 with php7. In my apache config, there is a redirect rule like the following: RewriteCond %{HTTP_HOST} !^www.* RewriteRule .* %{HTTP:X-Forwarded-Proto}://www.%{...
Stephan Richter's user avatar
0 votes
1 answer
107 views

apache2 append www to https url

I have an apache2 webserver in AWS using bitnami. In my bitnami.conf file I need to rewrite all URLs to https://www.example.com I am able to redirect the following correctly mydomain.com http://...
Paddy Mahadeva's user avatar
0 votes
2 answers
880 views

Why doesn't this .htaccess file redirect properly?

I have a web application with multiple pages. The .htaccess file redirects everything after the domain-name.com/ to my index.php file, which processes the input and renders the appropriate page. ...
Ryan Griggs's user avatar
  • 1,033
0 votes
1 answer
9k views

Rewrite cond for domain and www.domain letsencrypt

I have this virtualhost in /etc/apache2/sites-available/cv.conf <VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/cv/web <Directory ...
onda47's user avatar
  • 103
1 vote
2 answers
2k views

Unsure what this .htaccess set of rules is doing

I've inherited a web application, and in it is the following set of .htaccess rules. It appears to me that they do nothing. Can someone explain what they're doing? To me, it looks like they're ...
e_i_pi's user avatar
  • 223
1 vote
0 answers
113 views

Referrer Spam from Encoded URLs

I'm trying to prevent referrer spam to a number of websites I run. Then I encountered a lot of lines like this in the log files. \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd0\xba\xd0\xb0.kz I'm ...
GeoffAtkins's user avatar
0 votes
1 answer
1k views

Add www to domain but not for a specific domain

I've the following code in my .htaccess file: RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] The code above is for adding www to the domain if it does not ...
Igor's user avatar
  • 135
4 votes
1 answer
4k views

rewrite / restrict specific domain name in apache

We have https://example1.com/login and example2.com/login being hosted from the same apache server (2.2.22). I want to restrict /login on example1.com. example1.com/login --> 404 (preferably) or 403 ...
akay's user avatar
  • 53
3 votes
1 answer
10k views

Drop trailing slash in apache for directory

I have the following url www.example.com/advice/ now notice the trailing slash at the end of the url? I would like that to be removed to be something like www.example.com/advice. Now when I enter that ...
Steve's user avatar
  • 135
2 votes
2 answers
411 views

.htaccess is stopping a site from works while WP sites does work, why?

I have three sites running in a shared hosting (Bluehost) with a dedicated IP address. The description is as follow: example.com => this is the main site and domain, is a WP example.net => this is an ...
ReynierPM's user avatar
  • 722
1 vote
1 answer
550 views

Combining more then 1 Apache rewriterule: virtualhost domain redirect and inputfile redirection

I got stuck on using Apache's RewriteCond and RewriteRule conditions. I usually don't use them a lot and mostly the documentation provides me enough information to produce a solution by my self. This ...
Jeroen Maathuis's user avatar