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

How to load requested file from sub-directory without rewriting base

Utilizing .htaccess rules, I'm attempting to load a file from within a sub-directory while keeping the frontend URL unchanged if both the domain and file path match criteria. Example of URL: example.com/specificfile.xml The file itself is within a…
sparecycle
  • 459
  • 1
  • 6
  • 19
1
vote
2 answers

After removing .htaccess can no longer access phpmyadmin

Raspbian running on raspberrypi 3+ apache 2.4 I was trying to secure my server a little better and I enabled .htaccess by changing apache2.conf line AllowOverride None to AllowOverride All and added a .htaccess file to phpmyadmin path located at…
1
vote
1 answer

After installing script all subdomains go to the main domain

I have a main domain www.example.com. and the following subdomains under the main domain support.example.com test.example.com Previously both subdomains are working fine. But after installing a PHP script on the main domain, only the main domain is…
srisree
  • 11
  • 2
1
vote
1 answer

Replace AuthUserFile with the password itself or reference a relative path to the folder

I have a PHP script that generates 100s of directories and in these directories contain CSV files. I'm able to protect these CSV files using AuthUserFile if it points to an absolute .htpasswd file, but I want to point to a custom generated .htpasswd…
1
vote
1 answer

Allow files to be listed when viewing a directory but protected (via HTTP authentication) when accessed directly

I created a password protected directory using .htaccess and .htpasswd, but the files don't show up when I go to the directory URL. I have this in my .htaccess: #Protect multiple files AuthName "Dialog prompt" …
1
vote
1 answer

How do you redirect URLs with a query string with htaccess?

I want to redirect pages like : example.com/fr/opportunites/?sector_cat=bourses-detudes&ajax_filter=true To example.com/fr/bourses-detudes/ the second page is a post type page created with WordPress Is there any possibility to do that with…
LH AL
  • 11
  • 1
  • 3
1
vote
1 answer

2 websites hosted on same domain, 1 needs to look like a subfolder ( /blog)

I bought a VPS for my new project running apache. On it I have 2 websites on the same domain. The first one is Ruby on Rails /var/www/html The second one is Wordpress /var/www/blog I want Wordpress to act like a subdirectory of ruby ( /blog). Ruby…
Adelle
  • 13
  • 3
1
vote
1 answer

.htaccess redirect empty directories to index.php but it's showing function name instead of executing it

Hi I have a LEMP Server and I have used .htaccess file as bellow to redirect empty directories to index.php but the problem is that it's not executing the code in the index.php it's just printing the Array() .htaccess file RewriteEngine…
1
vote
1 answer

Issues with Require IP on Apache 2.4 and Ubuntu 20.04 server

I have setup a subdomain (staging.callkneehill.ca) on my server and have created a .htaccess file with the following parameters: Require ip 70.65.194.109 ErrorDocument 403 "Restricted Access" When I try accessing the…
Mike Hermary
  • 131
  • 7
1
vote
1 answer

PHP processing pages for forms not following line with rest of files

I'm a web developer hobbyist. I'm over 50, never had a true web dev job but like to tinker in my spare time for fun. That said, I have a web site hosted by Bluehost that I wrote with PHP from scratch. I actually enjoy the functionality better than…
Bob Todd
  • 13
  • 3
1
vote
1 answer

Redirect the document root and a specific page only to another domain

Might sound confusing, but what I want to achieve is this: If the user visits: www.mydomain.com (with or without www.) transfer them to: www.myotherdomain.com/welcome-old-users At the same time, I want to achieve this: If they…
1
vote
1 answer

.htaccess redirect based on the visitors host name, not IP address

I have done several attempts to figure out how to redirect visitors from the visitors hostname to some other place. I know with IP this works: RewriteCond %{REMOTE_ADDR} ^185\.93\.180\.* [OR] RewriteCond %{REMOTE_ADDR} ^188\.143\.232\.31 RewriteRule…
1
vote
1 answer

Apache Do Action Only If Path Contains

I'm using the following in an .htaccess to remove the extension from .php files: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] It works great, but how can I write a conditional statement so that it only…
GTS Joe
  • 199
  • 2
  • 10
1
vote
1 answer

Cakephp, App's folder not in the webroot why?

Why store the CakePHP files outside of the webroot? For example, this is the way way that I have always been told to do it. /home/username /app /cake /public_html index.php I know its because of security, but why? its not like the…
Steven Smethurst
  • 339
  • 1
  • 4
  • 11
1
vote
1 answer

Apache rewrite causes server error 403 when genuine directory exists after extension removal rewrite

I've spent a couple of days now trying to create a specific rule set that will allow me to remove .html extensions from all the files in the directory and present neater URIs. I'm using a .htaccess file in the root directory of that website and the…
iratefox
  • 13
  • 3
1 2 3
99
100