Questions tagged [mod-rewrite]

mod_rewrite is a URL rewriting module for the Apache web server. It is commonly used for so-called "pretty" URLs because of its ability to redirect on the server side (transparent to clients and their browsers), but also provides the power and flexibility to perform various request handling tasks beyond simple substitutions.

Filter by
Sorted by
Tagged with
1 vote
0 answers
519 views

AH10411: Rewritten query string contains control characters or spaces

How to reproduce the error: -- A space in my URL will trigger the error. Observation of the error: -- It seems to happen suddenly since around 3/10. ---- I did not upgrade my Apache version, but it ...
  • 11
6 votes
1 answer
677 views

RewriteRule started returning 403 Forbidden error

I have a website that uses a set of quite simple RewriteRules of the format: RewriteRule ^p/(.*)$ /product.php?$1 [L] All was working well and still is working perfectly fine on localhost. For some ...
0 votes
1 answer
35 views

Remove sub folder name from URL

http://example.com/portal/reports/data.php?id=2 In this URL I want to hide portal folder in the url/: http://example.com/reports/data.php?id=2 How can I achieve this using mod_rewrite? I used online ...
1 vote
1 answer
48 views

Redirection of Spams hacked page 404 to 410 .htacess

My website has been spammed by hackers for maybe 1 year. So now I have to update everything I think. And it seems that the page targetted by spammers is going to 404. My question : I tested this ...
  • 11
2 votes
1 answer
53 views

.htaccess redirect php WHMCS cart ID

For WHMCS I am trying to redirect products to another ID and subdomain. How can I create a .htaccess that will redirect https://www.example.com/clients/cart.php?a=add&pid=17 to https://clients....
  • 123
2 votes
1 answer
113 views

Problem with Apache rewrite with wildcard domains

I have a PHP app on Apache2 that is supposed to treat subdomains on the code level. My goal is to redirect any wildcard subdomain to the main domain's index.php. I do not use .htaccess. I searched ...
  • 21
1 vote
1 answer
80 views

Website not working due to htaccess

My website was fine (apologies in advance for not being a webmaster or developer) until SSL was enforced through hosting platform - a 500 error code/page showing internal server error. Spoke to ...
4 votes
1 answer
193 views

Handling # uri fragments as regular requests

So I have a one-page website with multiple sections and IDs. Right now, in the nav, I have it going to #about to jump them down to a section with ID=about But I want the user to be able to go to ...
2 votes
1 answer
65 views

How to rewrite a request to different files based on the domain name in ".htaccess"?

I run the website https://www.1.example. The contents of my .htaccess file are as follows: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ \...
  • 21
4 votes
1 answer
350 views

Modify rewrite rule to match ONLY directories, NOT directories AND files

I have the following rule in my .htaccess file: RewriteRule ^[^/].*/(dir1|dir2|dir3)(.+) $1$2 [QSA] It works great for the directories except sometimes it conflicts with files. How can I modify this ...
  • 153
1 vote
1 answer
34 views

Odd slash added at start of file folder in Apache rewrite

I'm working with an Apache rewrite statement that reads: RewriteRule ^((?!%{HTTP_HOST}).*)$ ${US_ROOTF_WWW}/www.%{HTTP_HOST}%{REQUEST_URI} [L,E=PROJECT_PREPENDED:1] The value of {US_ROOTF_WWW} is C:/...
  • 11
5 votes
1 answer
156 views

Htaccess Hotlinking Prevention: Exclude a specific image from rule

I have a working hotlinking prevention in the .htaccess. Everything works fine. However, I use an image of my website in email signature. After the hotlinking prevention, this image is now displayed ...
  • 141
3 votes
0 answers
102 views

Automatic display of WebP images instead of JPG images via Htaccess

I use Wordpress, the plugin "EWWW Image Optimizer" creates from JPG images automatically also WebP versions (example: From the image image.jpg is also an image image.jpg.webp created). The ...
  • 141
1 vote
1 answer
43 views

Old alternative domain names -- is it actually worth setting DNS to resolve at the website?

Someone noticed a problem with a site I manage in that somewhere all the old alternative domain names which we keep paying for were in the Google search results. Some problem had come up somewhere ...
  • 165
0 votes
0 answers
45 views

Run .htaccess rule to remove trailing slash only if such a file exists

I have the following .htaccess rule but I would only like it to run it if a file exists without the removed trailing slash: RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] I use ...
2 votes
1 answer
171 views

Non-ascii characters in RewriteRule :alpha:

I have RewriteRule ^([[:alpha:]]+)$ do-something.php?parameter=$1 and it works for URLs like .../Virtanen. For .../Mähönen I can use ([ÄÖäö[:alpha:]]+, but that of course fails for, say, .../Vadén. ...
1 vote
1 answer
455 views

Rewrite three URL directories to corresponding PHP files and pass subdirectory as a parameter

I want to convert the following https://example.com/download-file/xyz https://example.com/download-code/abc https://example.com/developer/mno to https://example.com/download-file?name=xyz https://...
  • 1,254
2 votes
1 answer
351 views

custom 404 page not work Apache/2.4.51 if missing is in a virtual subdirectory (Debian)

this is my first question here, I hope to find a solution. I have a problem with page 404 when the missing page is in a sub "virtual" directory, is used to pass a value to php, in ...
1 vote
1 answer
282 views

Redirect AMP Parameter To Its Permalink caught in Redirect loop

I have the same issue as mentioned on Redirect AMP Parameter To Its Permalink, the solution given by Mrwhite solved my problem and everything went fine # Redirect old "amp" URLs back to ...
2 votes
1 answer
280 views

Redirect AMP Parameter To Its Permalink

I have a similar situation as described in Handle "amp" in URLs from a now removed WordPress plugin the difference is I don't use custom post permalink /%postname%.html but just /%postname%...
  • 23
4 votes
1 answer
289 views

Why rewrite to index.php is not working on a wordpress site?

So my rewriterule is like RewriteRule ^test$ index.php [L] I tested it on https://htaccess.madewithlove.com?share=b0a9904b-1ec4-49cd-917c-36426ff6150a it works fine. I also tested it on live Joomla ...
  • 495
3 votes
0 answers
34 views

.htaccess not redirecting me to correct place

I have a website which opens to /resources/Installer/index.php but the path I need it to open to is /Installer/index.php. I have asked my webhost to help but they have said they cannot help. I have ...
2 votes
1 answer
35 views

Create a virtual index file to prevent 403s

I'd like to serve (httpd) either 404s or 200s instead of 403s. I found a way to redirect and change 403s so they become 404s but I'm not trying to replace 403s altogether but rather where they are ...
  • 73
3 votes
1 answer
298 views

How are slashes added between htaccess mod_rewrite variables

I was looking at two different variants of redirects: RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] And noticed that in the first ...
2 votes
1 answer
54 views

How do I match string in URL path at any level to specific file using mod_rewrite

It's likely that I missed the answer already because I'm not even sure how to phrase this, but here it goes... I'm attempting to create a healthcheck virtual--something "file", maybe, so ...
  • 73
2 votes
2 answers
153 views

Apache maintenance page htaccess without being overriden by subfolder

I want to perform a maintenance on my website, so wrote an htaccess (I do not own the server) to redirect users to a specific page. <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{...
1 vote
1 answer
279 views

HTTP to HTTPS Apache redirect doesn't work when used with other redirects

I have been asked to help with an OpenCart 1.5.6.1 installation on shared hosting with some redirection requirements. Some of the redirects were already present and I'm not sure if they are required ...
2 votes
1 answer
247 views

Why is this .htaccess evaluating to 302 redirect instead of internal rewrite?

As an example, I was expecting this https://example.software/credits to evaluate to an internal rewrite https://example.software?mode=credits Why is it showing up on the browser url-bar as a 302 ...
  • 1,254
2 votes
1 answer
210 views

How can I rewrite a URL to use a new path for Apache?

How can I rewrite a URL so that following is achieved: example.com/old/index.htm is redirected to example.com/new/index.htm ? I've tried to add the following RewriteRule in my server config vhost to ...
  • 297
3 votes
1 answer
348 views

ServerAlias directive not working on Apache 2.4.49

I have an instance of WordPress set up at https://wordpressinstance.example. I have an instance of MediaWiki set up at https://mediawiki.wordpressinstance.example. The MediaWiki instance is ...
2 votes
1 answer
116 views

htaccess - RewriteCond is met, but RewriteRule doesn't run

I am trying to match both a filename and querystring in my .htaccess file. When using an online testing tool (this one), it tells me that the conditions are being met, but the following rule doesn't ...
  • 23
2 votes
1 answer
373 views

Block access to multiple files with .htaccess - RewriteRule and FilesMatch fail

I am trying to block access to specific files. Neither the RewriteRule or FilesMatch rules I have tried work on the live server, it serves the files as normal with status 200 OK (I'm expecting 404 ...
3 votes
1 answer
129 views

sitemap.xml and serviceworker.js are location-sensitive files. But sensitive to the location in the request path or to the actual filesystem location?

I really like the idea of using .htaccess rewrite rules in combination with the /.well-known/ folder for keeping my webspace tidy and coherently / consistently organised. For instance, I know that ...
2 votes
1 answer
462 views

Redirect requests on alternate port for Apache virtual host

I have Apache server where I make my LoadBalancer for my application sereres through proxy and balancermember. Some of my clients come from legacy access, they use a port in the URL example.com:2030 ...
1 vote
1 answer
435 views

multilingual hreflang & .htaccess

I have found several questions concerning multilingual websites and .htaccess rewrite rules. Unfortunately I am only dealing with my website once a year and I am unable to interpret those answers to ...
2 votes
1 answer
66 views

301 Redirect from URL with query string to new URL without query string

I'm having trouble working out how to do a 301 redirect from: https://www.example.com/catalogue/catalogue.php?catSection=1 to https://www.example.com/hire-category/access-support-equipment/ I've tried ...
1 vote
1 answer
60 views

Htaccess redirect rule adds an unwanted variable

I'm trying to redirect logged-in users that land on a page to another page, but the redirect keeps adding the logged-in user's name to the path / URL. Say I'm logged in as Mario. The redirect ...
  • 63
3 votes
1 answer
119 views

IIS rewrite rules for SEO friendly URLs don't work in .htaccess for Apache

I'm using a Pi 3 for the Apache server but I can't figure out how to setup .htaccess. Previously I used IIS with which it is easy to implement SEO-friendly URLs. Linux .htaccess is very different and ...
4 votes
1 answer
832 views

Cookies for www and non-www different

I just discovered that cookies for www and non-www are different. I now understand that the browser treats example.com and www.example.com as two different domains. In detail, how can I assure that ...
  • 141
2 votes
1 answer
3k views

Redirect from index.html to its directory using .htaccess?

For each page of my website, it is named index.html and stored inside a folder of the name of the page. example.com/ serves example.com/index.html example.com/about/ serves example.com/about/index....
1 vote
1 answer
42 views

Subdomain rewrites without using certs that don't support sub domain affecting

I am using LetsEncrypt to generate and renew my certs for my website. Unfortunately, it does not support subdomains. Having said that, I have a ton of rewrite rules that work fine. For example: ...
1 vote
1 answer
141 views

Htaccess - replacing a query string with a numeric value

I don't know why but this htaccess item doesn't work for me. I have something like this after update user profile public/user_profile/show_user.html?id=4 and I want to have public/user_profile/...
2 votes
1 answer
578 views

How can I rewrite all Files to the Index Folder and also Remove the Extensions

I've been looking for a solution for a few hours now, and I'm struggling to understand why the Regex doesn't act like Regex... If you just try to match a letter, it doesn't match a letter, and I can't ...
2 votes
1 answer
317 views

Apache doesn't redirect subfolders

I'm having trouble configuring my Apache server through the .htaccess file. I want to redirect all request from my domain (example.com, www.example.com, example.com/folder1/folder2) to my new domain (...
2 votes
1 answer
1k views

Htaccess RewriteCond based on environment variable

I find apache very unfriendly. Anyway. I have this: RewriteRule (.*) - [QSA,E=DOMAIN_NAME:localhost.com] This doesn't redirect, which is fine: RewriteCond "www.%{ENV:DOMAIN_NAME}" "!=...
  • 127
2 votes
2 answers
270 views

Point all to index.php conflict with a private directory

Here is my website structure (root): private public .htaccess index.php The htaccess file contains: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ /index.php [L] Having this said,...
  • 127
4 votes
1 answer
166 views

Mod Rewrite Multiple Query String

I'm having trouble using modrewrite to redirect a URL with multiple strings. I have a PDF handling script. I want to redirect something like: https://www.example.com/pdfs/samplepdf.pdf/open [or /...
4 votes
1 answer
356 views

Rewriting a folder name using .htaccess doesn't want to work

I am wondering, why folder renaming doesn't work. RewriteRule ^pl/(.*) public/$1 Let's say I have a URL like: example.com/public/index.html Now I want to rewrite the URL to example.com/pl/index.html ...
2 votes
2 answers
71 views

Excluding homepage from Rewrite rules in htaccess

I would like to have this new prerendering service I'm using NOT apply its magic to the homepage and basically only to pages that begin with https://thechartcast.com/episodes/. Below is the relevant ...
  • 823
2 votes
1 answer
42 views

htacces rules for mobile and desktop site

I have a site that stores an index.php for desktop computers and a mobile.php for mobile devices. Both files are in the same directory (say /var/www). As default the user accesses index.php and if ...

1
2 3 4 5
13