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 votes
1 answer
70 views

htaccess and redirects

I'm wanting my URL to resolve to https://example.com if the visitor is typing in the URL with http://www or http:// or https://www Right now I have a redirect in my htaccess and it works but I get ...
Chris J. Popp's user avatar
0 votes
0 answers
132 views

Can't Find a Solution for Removing Trailing Slash at End of Directory URL

Please help me get my URL folders to point to index.php without a slash at the end. I tried this guide, but all I get is a URL with the slash at the end of it. The computer displays the right page, ...
Neo's user avatar
  • 1
1 vote
1 answer
187 views

htaccess redirect with negated conditions

Simple redirect in .htaccess works: #Redirect 302 / https://domain.toberedirected.com But the conditional one doesn't. I want that if the remote user IP address is in the list then ignore the ...
user109077's user avatar
0 votes
1 answer
184 views

How to use mod-rewrite for SEO friendly get params?

At present the webpage accepts get params like this https://TripTale.in /details.php?id=AlphaNumericKeys Which I want to make it look like https://TripTale.in /details/someTexts/AlphaNumericKeys ...
Sourav's user avatar
  • 123
2 votes
0 answers
50 views

Redirect the bare domain to a subdomain and still make the bare domain appear to users to fix a CSP error that occurs when using the bare domain?

I'd be grateful for some guidance with URL redirects in the .htaccess files as I'm not sure how to handle (though I hope it's straightforward). I've installed a site into a subdomain, let's call it ...
woof's user avatar
  • 21
2 votes
1 answer
85 views

.htaccess rewrite does not work with adwords gclid passed to the final url

Have a problem with traffic coming from Google Ads. A have a redirect roll that redirects https://example.com/some-words-words-aktivitet/ to https://example.com/index.php?mobile=1 (RewriteRule ^some-...
user3699041's user avatar
7 votes
2 answers
6k 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 ...
Chi's user avatar
  • 71
8 votes
1 answer
3k 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 ...
Jimbo Vader's user avatar
0 votes
1 answer
106 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 ...
Ram Gowda's user avatar
1 vote
1 answer
137 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 ...
JIRAKO's user avatar
  • 11
2 votes
1 answer
132 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....
Toodarday's user avatar
  • 123
2 votes
1 answer
517 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 ...
igalsc's user avatar
  • 21
1 vote
1 answer
83 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 ...
The Nowhere Kids's user avatar
4 votes
1 answer
233 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 ...
Josh Holly's user avatar
2 votes
1 answer
323 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 ^(.*)$ \...
Bartosz's user avatar
  • 21
4 votes
1 answer
683 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 ...
John's user avatar
  • 153
2 votes
1 answer
42 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:/...
missenc's user avatar
  • 21
5 votes
1 answer
326 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 ...
dajana.s's user avatar
  • 141
3 votes
0 answers
203 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 ...
dajana.s's user avatar
  • 141
1 vote
1 answer
48 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 ...
ja_him's user avatar
  • 165
0 votes
0 answers
114 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 ...
Ryder Cragie's user avatar
2 votes
1 answer
326 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. ...
Jori Mäntysalo's user avatar
1 vote
1 answer
792 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://...
Rohit Gupta's user avatar
  • 2,241
2 votes
1 answer
669 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 ...
A. Neodizzi's user avatar
1 vote
1 answer
423 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 ...
Anton Nb's user avatar
2 votes
1 answer
453 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%...
takraw's user avatar
  • 23
4 votes
1 answer
495 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 ...
Wen Shenk's user avatar
  • 505
3 votes
0 answers
63 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 ...
Malik157's user avatar
2 votes
1 answer
61 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 ...
Vita's user avatar
  • 73
3 votes
1 answer
482 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 ...
PixelSnader's user avatar
2 votes
1 answer
105 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 ...
Vita's user avatar
  • 73
2 votes
2 answers
267 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 %{...
billdangerous's user avatar
1 vote
1 answer
547 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 ...
authentictech's user avatar
2 votes
1 answer
512 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 ...
Rohit Gupta's user avatar
  • 2,241
2 votes
1 answer
765 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 ...
wouter205's user avatar
  • 317
3 votes
1 answer
639 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 ...
JohnRDOrazio's user avatar
2 votes
1 answer
197 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 ...
Adriano's user avatar
  • 23
2 votes
1 answer
642 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 ...
chris.dempsey's user avatar
3 votes
1 answer
159 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 ...
Rounin's user avatar
  • 2,325
3 votes
1 answer
1k 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 ...
Gustavo Oliveira's user avatar
1 vote
1 answer
638 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 ...
Bravewart's user avatar
2 votes
1 answer
165 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 ...
webfooted's user avatar
1 vote
1 answer
203 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 ...
Gottano's user avatar
  • 63
3 votes
1 answer
174 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 ...
Puneet Sharma's user avatar
5 votes
1 answer
1k 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 ...
Alan's user avatar
  • 151
2 votes
1 answer
5k 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....
Tim Wilson's user avatar
1 vote
1 answer
93 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: ...
user1970839's user avatar
1 vote
1 answer
349 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/...
Mantykora 7's user avatar
2 votes
1 answer
948 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 ...
Mister SirCode's user avatar
2 votes
1 answer
387 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 (...
Jose A. Matarán's user avatar

1
2 3 4 5
13