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

Redirect www to non www and redirect to index.php

my www folder has the following .htaccess RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] my api folder (within the www folder) has the following…
2WFR
  • 135
  • 1
  • 7
1
vote
1 answer

How do I add the __Secure prefix in this .htaccess line?

Sorry, I'm not an Apache expert. I need to add the __Secure prefix to this htaccess line: Header onsuccess edit Set-Cookie (.*) "$1; SameSite=Strict; Secure" is this possible? How?
1
vote
1 answer

How Can We Do 301 Redirect Of Over 200 Pages To Corresponding 200 Pages At New Location?

I need help and need it fast. We recently migrated a subdomain to integrate with the domain. Eg. https://blog.example.com to https://www.example.com/blog https://blog.example.com has a ton of traffic which we don't want to lose. So we need to do 301…
1
vote
3 answers

Apache: How to "hide" a subdomain but serve over https

I will freely admit my ignorance - or perhaps enough knowledge to be dangerous. I have a subdomain http://db..com that serves the phpMyAdmin utility. It's currently in a directory with an Apache directive to require a valid-user from…
Eddie Rowe
  • 43
  • 1
  • 5
1
vote
1 answer

Apache mod_rewrite RewriteRule loops despite L flag

Apache/2.4.54. I am trying to achieve that similar URLs (e.g. "/anystuff.htm") are externally redirected to "/something" which internally is "something.html". But the following rules cause a loop instead of stopping, i.e. "something" is…
handle
  • 113
  • 3
1
vote
0 answers

Setup Authentication for landingpage fetching data from proxy via access restriction?

Imagine the scenario where you have a client who wants you to implement calls to an external API on a landingpage that you've setup for them. The external API works based on a contract and API keys which are obtained through that contract; hence you…
DevelJoe
  • 187
  • 3
  • 11
1
vote
1 answer

Additionally, a 404 Not Found

A try to make my own errordocument on Localhost... In my .htaccess: ErrorDocument 404 /errors/404.php In the errros directory: 404.php The .htaccess in the root directory. But if i tpye some invalid url, like: http://localhost/test/index.pXX, then i…
Holian
1
vote
1 answer

htaccess syntax issue when moving script to a subfolder

I have recently purchased a script but this script only works in public_html folder . I need to install it in a subfolder named shop ( public_html/shop/ ) . Now the following .htaccess rules work perfectly when the script is placed in public_html…
Mr Pro
  • 33
  • 3
1
vote
1 answer

htaccess, block access a url with parameters

If I want to block access to example.com/path/?xxxx (xxxx is variable), but allow access to example.com/path/, how should I write it in my .htaccess?
Sanata
  • 11
  • 3
1
vote
2 answers

Turning HTTPS on via .htaccess

I currently have a site where I am using .htaccess to turn https on for certain sections of the site: RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (evaluate/purchase*) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} There are several…
1
vote
1 answer

RewriteCond rules from apache to nginx

RewriteCond %{TIME_SEC} >40 RewriteCond %{TIME_SEC} <56 RewriteRule ^(.*)the-product(.*)$ https://www.%{HTTP_HOST}/%{REQUEST_URI} [R=301,L] I want to convert it to nginx but there is no solution for it to run for a fixed time RewriteCond…
Long MMO
  • 11
  • 2
1
vote
1 answer

.htaccess redirect if param value not portuguese-pt (FORCE WHMCS ONLY ONE LANG)

I need help to redirect URLs with multiple language codes to one with .htaccess. The following URLs should…
1
vote
0 answers

Redirect docroot for specific URI path by .htacess

Is it possible to redirect a specific URI path to a specific docroot within the original docroot using the .htaccess? For example: example.com > docroot Where example.com/path > docroot/subdir
Eng7
  • 127
  • 1
  • 7
1
vote
0 answers

Automatically remove Set-Cookies

I have a php web application. This web application sets some cookies. I want to write a .htaccess which remove on the fly this cookies. Here is what I've done, with mod_header: Header unset Set-Cookie It works fine, but I have a problem: This line…
Bob5421
  • 319
  • 3
  • 8
  • 16
1
vote
1 answer

How to move site to a sub directory and 301 redirect it?

I have changed my site path from root directory to a subfolder. Eg: example.com to example.com/subfolder and everything is working fine. but now I want to 301 redirect old URLs to New URLs. Eg: redirect example.com/how-to-play-football to…
CodeXoro
  • 11
  • 2