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

Condition depending on domain in .htaccess: SetEnvIf and IfDefine?

I would like to add a rule in .htaccess that "Does something" (actually enable a httpauth user restriction) depending on the domain name. I thought I had it and did: SetEnvIf Host "staging\.(.*)\.ch"…
1
vote
0 answers

How to remove number from the URL?

I have wordoress site where I am getting /1 in the URL. I have checked siteurl,homeurl,permalinks but not sure why /1 is getting added in the URL e.g…
1
vote
0 answers

when it goes to https:/... directly it is missing the referer part

it's all about cookies ,it suppose redirect to ?referer_id=186 every time which is refresh the cookies of new logo but i notices when user delete or clear the history of Brower and try to visit the website by https the cookies not refresh again you…
1
vote
1 answer

Apache outputs all urls of a second domain as a subfolder of the primary domain name

Would anyone be able to possibly give me some guidance? Basically, I have a 'shared hosting' account with a large internet hosting provider, and my account lets me have multiple separate domains within this folder structure. (Note: not aliased…
1
vote
1 answer

Local .htaccess strangely allowed running PHP in CGI/FastCGI mode in Apache under shared hosting environment

I am using a shared web hosting service. Running phpinfo, I can see the Server API shows CGI/FastCGI rather than Apache 2 Handler. In this article: http://docs.joomla.org/Should_PHP_run_as_a_CGI_script_or_as_an_Apache_module%3F It says 'If your…
bobo
  • 599
  • 2
  • 8
  • 24
1
vote
1 answer

Using an htaccess file for 410 (gone page) prevents use of images

I am shutting down a website. I have deleted the wordpress site and the only page left in the domain is a page announcing the permanent shutdown of the site. The URL of the shutdown page is... http://mydomain.co.uk/index.htm there is also a folder…
1
vote
1 answer

Redirect to folder only if root from other site referrer

I have a redirect from root to subfolder. If user visits https://example.com it redirects to https://example.com/subfolder. But I want it not to redirect if referrer is my site, so user can reach root page. For example: User visits…
1
vote
1 answer

Setting Apache header with conditions of excluding paths/directorys / server ips

I use a WordPress plugin called Duplicator Pro and the best way of installing with their installers is to use the servers IP rather than the domain because that way it autofills & conects to the server easier, while also not triggering multiple…
Ryflex
  • 139
  • 1
  • 11
1
vote
1 answer

On Apache how to switch off DirectorySlash only for requests to a specific subdomain?

Served by Apache I'd like on one subdomain site of mine (say sub.mydomain.com) that URLs without trailing slashes point directly (without external redirect) to the index file in the underlying folder. The subdomain requests are internally redirected…
halloleo
  • 123
  • 7
1
vote
0 answers

How do I convert this .htaccess snippet to Nginx rules?

I have this snippet of .htaccess coming from Apache: RewriteCond %{REQUEST_FILENAME} index\.php RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ RewriteCond %{DOCUMENT_ROOT}/u_pages/%1.php -f RewriteRule .* u_pages/%1.php? [L] Using the Winginx online…
Trace DeCoy
  • 153
  • 2
  • 6
1
vote
2 answers

restrict access to a specific URL with .htaccess

Hello i am running server with xenforo. i would like to know how can i restrict url from .htaccess. Url is :…
mikef0x
  • 13
  • 3
1
vote
1 answer

Apache: not working (in .htaccess)

I am trying to set some controls in Apache via the .htaccess. This works: Order allow,deny Allow from all Deny from all while this does not: Order allow,deny Allow from all …
1
vote
1 answer

Forbidden ... denying access to be safe

Total n00b here. I'm running a LAMP stack using Raspbian OS on a Raspberry Pi 4 Model B. I tried googling around, but I couldn't find a thread that matched my issue. My jenga tower seemed pretty stable. However, in the last week, I've started…
didvids
  • 11
  • 2
1
vote
1 answer

htaccess rewrite only in root directory (generically)

Hi I am trying to get htaccess to rewrite only if a file, symlink, or a directory is not present with that name. Which I have successfully done with this right here: RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l…
tony
  • 133
  • 5
1
vote
1 answer

Trying to get Apache to serve webp instead of png/jpg (from /img folder of prestashop)

First post here, so I hope I did it well. I converted all png/jpg starting from my prestashop public_html folder to webp, and added rewrite rules to the .htaccess in order to have the webp served instead of png/jpg. I based my rewrites on the…
Totoro
  • 13
  • 4