Questions tagged [.htaccess]

Directory-level configuration file found mostly on Apache web servers

The htaccess file is a supplemental configuration file used by Apache to modify the default configuration as it applies to the directory the htaccess file it in (as well as all the files and subdirectories in that directory).

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
Source: Apache manual

The directives allowed in htaccess files are governed from the main Apache configuration files by means of the AllowOverride directive.

The most common use is in conjunction with the mod_rewrite and security modules of the Apache webserver. Mod_rewrite allows URLs to be rewritten for scenarios such as the following:

  • Shortcuts such as example.com/info to redirect to another page
  • Redirects from old pages to new pages
  • virtual directories (directories which actually appear elsewhere in the file system)

The most common security applications are:

  • Password protection of directories and files

For more information see the mod_rewrite and aaa documentation.

2807 questions
1
vote
1 answer

What determines the name of Apache PHP Handlers?

When configuring an Apache server to use a Handler to run PHP code, I'm familiar with adding a line similar to below in httpd.conf or .htaccess: AddHandler application/x-httpd-php81 .php This tells Apache to use the named handler to interpret .php…
frumious
  • 123
  • 5
1
vote
0 answers

How to redirect all pages that contain an specific word using the .htaccess file

I have a bunch of indexed pages that start with the same word and they are all 404 so I want to redirect them all to the homepage of the site. The server is Apache, so I would like to use the .htaccess file. But the problem is that "the word" is not…
1
vote
1 answer

how to run next.js using NODE and react.js at the same time on apache server

I have to run 2 different apps on the same domain at the same time. I want to forward all requests to localhost:3000, if url contains /presscenter, if not, default should be my react.js application. I found this one here for apache virtual…
1
vote
1 answer

Default WordPress .htaccess rewrites causes default server page to load due to no default index page present for the root URL

I could really do with some help here please. I know this is a WordPress issue now through testing. If I allow .htaccess to process rewrites on my Wordpress sites by adding AllowOverride FileInfo to the https conf file, my WordPress sites all…
J O
  • 21
  • 4
1
vote
1 answer

How to replace custom url old domain to new domain with .htaccess

How to replace all url entire website with new domain and new permalink? I have 5k url to replace at my site. Example : Current URL: oldomain.com/2020/12/data-raid-4963.html Replace To: sub.newdomain.com/4963-2/ Current URL:…
1
vote
1 answer

Restrict access to specific http_host with apache 2.4.x .htaccess

I'm wondering if anyone knows how to approach this predicament I am facing using .htaccess. I have a website that is accessible using 2 different domains. For one of the domains, I only want the website to be accessible to a subset of IPs only…
Jim Smith
  • 11
  • 1
1
vote
1 answer

Trapping misformatted paths to Redirect to 404 instead of returning 403

Owing to an error long ago our company web site has been serving image URLs containing a significant amount of white space. E.g. http://www.example.com/ /assets/ProductPhotos/image.png Somehow, browsers have handled this…
1
vote
1 answer

how to redirect a web page based on domain name using .htaccess

At a site serving multiple domains (example.com, example.org, etc.), we would like to redirect a page depending on the domain: https://www.example.com/page1 => https://www.example.com/page2 https://www.example.org/page1 =>…
vision
  • 13
  • 2
1
vote
0 answers

Apache2: mod_ratelimit only allowing half the speed

I'm trying to limit the file download speed in a directory I've got the following .htaccess SetOutputFilter RATE_LIMIT SetEnv rate-limit 4096 But this only allows 2MB/s, on my browser and…
DrDino
  • 11
  • 1
1
vote
0 answers

Apache 2.4 "client denied by server configuration" caused by Require expr - even though the request succeeds

Our apache error log is littered with messages saying client denied by server configuration, even though the htaccess configuration is working as intended. Here is the relevant bit of the htaccess: SetEnvIfExpr "req_novary('User-Agent') =~…
Jonathan
  • 111
  • 3
1
vote
1 answer

Apache ToLower on all Wordpress pages (not PDF/CSS/JS)

I'm having issues performing a 301 redirection of URLs that contain capitals to lowercase, excluding static files (PDF/CSS/JS/JPEG/JPG/PNG/WEBP...etc). For example: https://www.example.com/Page/ would become https://www.example.com/page/ but…
1
vote
1 answer

htaccess redirect all subpages to parent page except for some parent pages

I want to match all subpages to parent pages, am using wordpress, will that mess up the images and wordpress files?, And I have tags and categories, and I want to exclude them from this rule. RewriteRule ^(.*/). https://www.example.com/$1…
1
vote
1 answer

Redirect all URLs ending in ".-detail" to remove the dot

I have a rather odd situation where our old URLs are ending in .-detail and need changing to just -detail. For example: example.com/product.-detail needs changing to example.com/product-detail In other words the . needs removing. I figured a…
1
vote
1 answer

Apache htaccess ruleset: Try request as: 1) file as-is 2) file + .html suffix 3) DirectoryIndex 4) Else to index.php CMS router

I'd like to express this ruleset If the request is /hello then try the following in the given order: /hello — File of that name exists (file without file extension). Edit: Not a necessity. Only a possibility/compromise. Drop if too…
porg
  • 143
  • 5
1
vote
1 answer

htaccess: 301 redirect defined URLs to new domain and catch all redirect the rest

I want to redirect some URLs from an old domain to new versions on a new domain. The old domain uses the www. subdomain and SSL. For example: olddomain.com/audi -> newdomain.com/cars/audi olddomain.com/bmw -> newdomain.com/cars/bmw But there are…
Cray
  • 135
  • 5