Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mod-rewrite]

URL rewriting module for Apache web servers

2
votes
2answers
42 views

Can't figure out a htaccess rule

I have this in my htaccess but can't figure out what its for. Because of the nature of rule, searching doesn't help either. RewriteCond %{REQUEST_URI} !(/$|\.) RewriteRule (.*) %{REQUEST_URI}/ [R=301]...
0
votes
0answers
12 views

Decoding a Rewritten URL using mod_rewrite - htaccess - regex

I am using Apache 2.4. I have set up and configured an Apache HTTP server, to host my invision app, my app is linked to external google docs. I am trying to redirect to an external google doc from the ...
1
vote
1answer
11 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\....
0
votes
0answers
23 views

PT rule in .htaccess in subdirectory that will be processed in .htaccess for parent directory [duplicate]

I have a PHP project that exposes its API under /api/public/(xyz). The http root directory has .htaccess file that rewrites those requests to be processed by index.php. For reason not relevant here, ...
2
votes
2answers
43 views

Apache HTTP 2.2: Setting cache header when query string version exists

I've found example of how to do this all over the web, but I haven't been able to get this to work. Want to set a long future cache time on requests that have a query string of something like ?v=123. ...
1
vote
0answers
15 views

HTTPS security warning for sub subdomains [duplicate]

I have an apache 2 server and I a wildcard https certificate for all my subdomains. But I do not have one for sub subdomains. Here's an example: https://example.com = secure https://...
1
vote
1answer
25 views

Apache mod_rewrite change domain extension

I want to have a 4 conditional mod_rewrite. http to https http://example.com to https://example.com www. to non-www. https://www.example.com to https://example.com non-plural ending to plural ...
0
votes
0answers
28 views

Rewrite URL after Symfony rewrites rules

The goal is to add the locale "en" at the beginning of the URLs which doesn't have it. Example https://example.com/document/file.php Becomes https://example.com/en/document/file.php The ...
1
vote
1answer
67 views

What is the difference between HTTP_HOST and HTTPS_HOST in apache .htaccess files?

I'm editing an .htaccess file.. In RewriteCondition for RewriteRules, HTTPS_HOST seems to only match urls that are accessed via https:// protocol (ssl). I saw in docs somewhere that it's a T/F ...
2
votes
1answer
24 views

Block requests starting by string

I would like to block all requests starting with /search?q= as they generate unwanted load on my server. Following this question https://stackoverflow.com/questions/4640807/how-to-block-bot-requests-...
1
vote
1answer
55 views

htaccess rule to protect against malicious post requests to WordPress index.php?pubkey=

I've been looking at a log created by a WordPress plugin called Bad Behavior and in it there are many entries from different IP addresses at various intervals during the day that are requesting the ...
1
vote
2answers
54 views

How do I handle a missing RewriteMap file?

I'm defining a RewriteMap in my Apache httpd configuration. (This is working correctly.) RewriteMap redirects-list txt:/path/to/redirects.txt But when the map file (/path/to/redirects.txt) doesn't ...
2
votes
1answer
38 views

Getting “302 Found” even after redirecting to a specific file in the .htaccess

I have an Apache server hosted on an EC2 instance which points to a domain that I own. Now, what I essentially want to get done is that the web server should return a .json file when the user tries to ...
2
votes
1answer
141 views

Redirect everything to language specific https sites

I would like to do the following redirection: Go to the English site if there is no data about language Go to the Hungarian site when the user's browser language is Hungarian Go to the English site ...
1
vote
1answer
57 views

Nginx friendly URL rewrite rules

I have recently migrated from Apache to Nginx and the performance is impeccable. The site is a download server (mainly) with a custom PHP script. Some example URLs are like: https://sub.example.com ...
1
vote
3answers
55 views

How do I hide a specified port from an URL?

I have one server on example.com, and I have another one on example.com:10001. When users try to reach example.com:10001 they end up on example.com:10001/index.php/login and that's how it should be. ...
2
votes
1answer
52 views

RewriteCond %{HTTP_REFERER} ∈ %{REQUEST_URI}

Is there a way to check using RewriteCond whether the Referer includes the requested URI or... RewriteCond %{HTTP_REFERER} == 'host.com/' + %{REQUEST_URI} ... ? I need to catch whether the surfer ...
1
vote
1answer
45 views

Htaccess - -remove parameters from url

I need remove a single parameter from url with htaccess from http://example.com/page/detail/page.php?name=franco&age=50 to http://example.com/page/detail/page.php?age=50 I am using this ...
1
vote
1answer
71 views

RewriteMap not working, nothing is rewritten (Apache 2.4)

I have a bit of a unique situation: I need to take a subdomain and make it redirect to a random selection of alternate domains, each of which is on a separate server. Think load balancing, except it's ...
1
vote
1answer
55 views

Virtual hosts on Apache not applying 301 redirect

I have a Ubuntu 18.04 server on an Amazon EC2 instance running Apache 2, with an SSL certificate installed, which I use exclusively to host virtual hosts for .tld variations of the policymakr.com ...
0
votes
1answer
66 views

Website stopped working - bad flag delimiters error

I've had a website that has worked for a year. I changed the domain name, and the hosting company copied all of the data to the new hosting account. The website worked for a few days. Now, with no ...
2
votes
1answer
41 views

How to remove mass trailing slashes(Nginx)

I need to remove mass trailing slashes, now I have rewrite ^/(.*)/$ /$1 permanent; So www.example.com/ becomes www.example.com. It's good, but when I go to www.example.com/// (any amount of slashes)...
1
vote
1answer
37 views

how to show wildcard subdomain content based on url by .htaccess file?

If the user enters example.domain.com, I want him to see what's in www.domain.com/example. Another example: User will request example.domain.com/photos/gallery.php?from=var1&no=3, he'll see ...
1
vote
1answer
20 views

Access an app's subfolder while the app is itself in a subfolder

I have an app (Symfony) in a folder rapp and I'd like to access via example.com/rapp/. The index.php file is in a rapp/public/ folder. So I'd like to have all my requests to /rapp/ to rewrite to /...
1
vote
1answer
39 views

Multiple mod_rewrite parameters for same php file

I want site.com/home/profile to map to site.com/index.php?view=home&type=profile and site.com/profile/a1b2c3 to map to site.com/index.php?view=profile&id=a1b2c3 and site.com/profile/...
0
votes
0answers
29 views

Apache URL redirect using RewriteMap [duplicate]

I am struggling with the last part, writing proper RewriteRule (maybe I also need RewriteCond?). I have this mapping.txt: apple 30/products/apple.png xerox 38/products/xerox-300.png dell 3021/...
0
votes
1answer
33 views

How to add the trailing slash in general for an Apache + CDN architecture (without using Apache mod_rewrite)?

I would like to add the trailing slash in general when it is absent in the request URL: when user requests https://example.com/blog, it should be redirected to https://example.com/blog/ when ...
0
votes
1answer
31 views

RewriteEngine rules ignored by Apache on SSL

I have a working Apache setup on CentOS 7.6 using the standard Apache 2.4.6-88 package, using HTTP. I am trying to enable HTTPS on the server, and everything works, except for my RewriteEngine rules. ...
0
votes
0answers
13 views

401 error site loads even if I successfully authorize

I am using the following .htaccess which has multiple functions. 1. show authentification box before a user can enter my website 2. add www to URL if URL starts without 3. Always redirect to `index....
3
votes
1answer
219 views

replace domain name in htaccess rule with dynamic hostname

I Have this rule in .htaccess: 1 ## Protect from spam bots ## 2 RewriteEngine On 3 RewriteCond %{REQUEST_METHOD} POST 4 RewriteCond %{REQUEST_URI} .wp-comments-post\.php* 5 RewriteCond %{HTTP_REFERER}...
0
votes
1answer
58 views

Apache destination virtual host certificate when using mod_rewrite or ProxyPass

I am trying to use mod_rewrite or ProxyPass to redirect (PT) the client's request from virtual host A on 443 to different virtual host B on port 4434, also with SSL. Like that: SSLProxyEngine on ...
1
vote
0answers
74 views

Apache SSL reverse proxy to a node server using websockets

Browsing to a root domain like https://sub.example.com and navigating through pages such as https://sub.example.com/page1 works. But only if I start my initial connection at the root. If I refresh ...
2
votes
1answer
120 views

htaccess change document root to /public and prevent /public from being used

I'm hosting a node app and my folder structure is like this: mydomain.com --index.js --package.json --public\test.txt I want to treat public as my document root and not allow anything above it to be ...
3
votes
1answer
93 views

How to exclude RewriteMap if REQUEST_URI is not found

I have an old site wordpress site I am in the process of migrating. There are about 50000 urls that need to be redirected. For this I am using DBM files which seem to be working fine, however during ...
1
vote
1answer
77 views

Apache2 - Only allow .pdf and index access in WebDAV

I've set up a WebDAV with apache2 in order to use it with Zotero. As we only want to upload and download pdfs over this webdav, I want to prevent the upload or download of any other files than pdf ...
1
vote
1answer
22 views

.htaccess priority between directives - return a 404 for missing static resources

On a WordPress installation, I want to immediately return a 404 (without a courtesy page) for missing static resources, but the directives seems to conflict. Can you help me to understand solve the ...
1
vote
1answer
57 views

Mod_rewrite is adding /var/www to the resulting url

I have some problems with the Apache mod_rewrite rules. Whenever I try to go to https://example.com// (see double slashes at the end) it redirects to a 301 page but it's adding the location of the ...
2
votes
1answer
226 views

Apache .htaccess RewriteRule and ErrorDocument

I have a .htaccess file : RewriteEngine On DirectorySlash Off RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.mp4|\.ttf|\.eot|\.woff)$ RewriteRule ^(.*)$ ?page=$1 [NC,L,QSA] ErrorDocument ...
3
votes
1answer
73 views

RewriteCond ignored in httpd.conf

Put simply this works in htaccess: RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] But when ...
0
votes
1answer
42 views

How do I tell the client the new filename with mod_rewrite?

I'm trying to convert requests like /download.php?name=one into /downloads/one.zip instead. The following sends the correct file, but the client saves it as download.zip instead of one.zip ...
4
votes
0answers
25 views

A little confusion about DBM files and how they work

I have apache 2.4 and am using RewriteMap DBM files. ie: <IfModule mod_rewrite.c> RewriteEngine On RewriteMap examplemap "dbm:/etc/httpd/conf/rewrite.dbm" RewriteCond ${examplemap:$...
1
vote
1answer
171 views

apache 2.4 - double encode already encoded query string in URL

I need help regarding a requirement. We have Apache 2.4.6 installed I have a URL which has an encoded query string: https://example.com/home?testStr%3Dhello%26id%3Drad I am trying to find out how ...
0
votes
1answer
65 views

Apache redirect Absolue url to relative url

So I want to load a web-app from a subfolder. Current configuration looks like this <VirtualHost *:80> ServerName YOUR IP ADDRESS/DOMAIN ServerAdmin webmaster@localhost ...
1
vote
1answer
28 views

Apache Rewrite not working

I have a very strange thing happening in my apache2 setup. I just want to redirect HTTP to HTTPS. I have tried all possible ways, like this: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?...
5
votes
1answer
121 views

Mixing DBM Rewrite and Redirect how to stop Rewrite if url is not in list

The scenario: I need to be able to both redirect certain urls and rewrite other URL's Right now after much tinkering I am able to get almost everything to work If I hit the example.com works ...
1
vote
1answer
298 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 ...
4
votes
1answer
128 views

RewriteMap dbm .dir .pag

I have been working with RewriteMap dbm, I was able to the text version working however cannot figure out how or why I am getting the error described below. The Virtual host: <VirtualHost *:80>...
0
votes
2answers
101 views

Apache2 URL Rewrite with Reverse Proxy

I've been trying to accomplish a goal of using Apache as a reverse proxy to translate HTTP to HTTPS as well as using mod_rewrite to inject a query string. The reverse proxy works if tested without ...
1
vote
2answers
245 views

ModSecurity SecRule based on original browser url, not internal rewrite (index.php, app.php, etc.)

I'm working on a Symfony 2 site, and am trying to create a ModSecurity rule to match a particular browser URL. IE example.com/results Symfony 2 internally rewrites all requests to app.php using ...
8
votes
1answer
736 views

HSTS and double redirect

I manage a little website in a shared hosting LAMP environment: this basically means the only thing I can edit is an htaccess file. I wanted to add HSTS support (and I did it), but, when I tested my ...