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
31 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 ...
user avatar
1 vote
1 answer
33 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 ...
user avatar
  • 165
0 votes
0 answers
18 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 ...
user avatar
2 votes
1 answer
101 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. ...
user avatar
1 vote
1 answer
33 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://...
user avatar
2 votes
1 answer
57 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 ...
user avatar
1 vote
1 answer
101 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 ...
user avatar
2 votes
1 answer
137 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%...
user avatar
  • 23
4 votes
1 answer
85 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 ...
user avatar
  • 485
2 votes
0 answers
29 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 ...
user avatar
2 votes
1 answer
29 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 ...
user avatar
  • 71
3 votes
1 answer
59 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 ...
user avatar
2 votes
1 answer
48 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 ...
user avatar
  • 71
2 votes
2 answers
96 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 %{...
user avatar
1 vote
1 answer
136 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 ...
user avatar
2 votes
1 answer
61 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 ...
user avatar
2 votes
1 answer
73 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 ...
user avatar
  • 287
3 votes
1 answer
116 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 ...
user avatar
2 votes
1 answer
54 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 ...
user avatar
  • 23
2 votes
1 answer
223 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 ...
user avatar
3 votes
1 answer
93 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 ...
user avatar
2 votes
1 answer
158 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 ...
user avatar
1 vote
1 answer
225 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 ...
user avatar
2 votes
1 answer
47 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 ...
user avatar
1 vote
1 answer
31 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 ...
user avatar
  • 63
3 votes
1 answer
101 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 ...
user avatar
4 votes
1 answer
511 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 ...
user avatar
  • 141
2 votes
1 answer
2k 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....
user avatar
1 vote
1 answer
35 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: ...
user avatar
1 vote
1 answer
80 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/...
user avatar
2 votes
1 answer
311 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 ...
user avatar
2 votes
1 answer
202 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 (...
user avatar
2 votes
1 answer
756 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}" "!=...
user avatar
  • 127
2 votes
2 answers
112 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,...
user avatar
  • 127
4 votes
1 answer
94 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 /...
user avatar
4 votes
1 answer
86 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 ...
user avatar
2 votes
2 answers
61 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 ...
user avatar
  • 823
2 votes
1 answer
39 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 ...
user avatar
1 vote
1 answer
89 views

Htaccess Using RewriteMap with a text file

I can't use link with * Example - http://localhost/photo_gallery/public/show_c.html/color-1* The requested URL was not found on this server. The others work's color-3, wood, etc. generated map - map....
user avatar
1 vote
1 answer
175 views

.htaccess url rewrite remove 2 id

Is it possible to delete 2 parameters ID of the url & just show the number. Currently i have url like this: http://localhost/photo_gallery/public/product_configurator.html?prometheus_id=10082&...
user avatar
2 votes
1 answer
32 views

Four 301-redirects from "www.example.com" to "shop.example.com" (am I losing my Google PageRank?)

Some years ago, I started my website with the main domain www.example.com. However, the project ended up being a store under shop.example.com. I obtained hundreds of links to http://www.example.com, ...
user avatar
  • 423
1 vote
1 answer
124 views

Url changing with htaccess

I have a web presentation with some typical url adresses. Now I need to add a rewriterule for a different languages, examples: domain/club -> do not change domain/club/path -> do not change ...
user avatar
1 vote
1 answer
142 views

Blocking bad bots based on useragent in apache conf

I am proposing blocking bad bots using the following code in /etc/sites-enabled/site.conf and I have a few questions. RewriteEngine On RewriteCond %{HTTP_USER_AGENT} useragent1|useragent2|useragent3 [...
user avatar
1 vote
0 answers
33 views

Modify rewrite rule to handle four ids rather than just one [closed]

I have rewrite rule which gives id from link to script and it works perfectly: RewriteRule ^index/viewproduct/id/(\d+)$ produkty/index.php?id=$1 [L] I need one more RewriteRule to handle URLS like: ...
user avatar
  • 21
1 vote
1 answer
562 views

.htaccess Rewrite Wordpress Subdirectory without breaking other subdirectories

So I have WordPress installed in /wp/ but I want all WordPress URLs to be rewritten to appear in the root directory. I currently have this working (see below) but I want to change my .htaccess so it ...
user avatar
2 votes
1 answer
897 views

Why does RewriteRule for "^//(.*)" (begins with double slash) not redirect to a single slash?

Have this rewrite rule in vHost context. But it does not rewrite requests that begin with //.* (double slash). Just serves them up from /.* (single slash) instead of responding with a redirect to /.* ...
user avatar
  • 143
2 votes
1 answer
859 views

301 redirect with regex: how to match any file at top domain level (not in a subdirectory)?

I need to redirect URLs of all .dmg files at domain's top level to specific folder. By way of example: http://example.com/file.dmg to http://example.com/downloads/file.dmg I can't hard code the domain ...
user avatar
2 votes
1 answer
88 views

Apache mod_rewrite in .htaccess

This should be a simple question. Checked Google but it listed nothing helpful. I use WP on one of my sites and it already generates a mod_rewrite section with: <IfModule mod_rewrite.c> ...
user avatar
1 vote
1 answer
101 views

Internal Server Error caused by rewriting [closed]

Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{...
user avatar
4 votes
1 answer
622 views

htaccess redirect root domain to subdomain with exceptions

i m using wordpress and want to redirect my root domain to a new subdomain and ignore urls that contains a certain string http://www.example.com/post.html To http://subdomain.example.com/post.html ...
user avatar

1
2 3 4 5
13