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

Should I escape slash '/' in RewriteCond?

Whether I need to escape the slash '/' in RewriteCond? Currently I write the following rule in .htaccess: RewriteCond %{QUERY_STRING} rp=/knowledgebase/ RewriteRule ^index\.php$ https://www.datanumen.com/knowledgebase/ [QSD,R=301,L,NC] However,…
alancc
  • 141
  • 12
1
vote
1 answer

Two different rewrite conditions in the same .htaccess?

I need to create a rewrite condition for two specific files, according to the requested path in the URL. It's possible? Condition 1: If the URL is example.com/admin go to admin.php?uri=params. That is: example.com/admin/form =>…
1
vote
1 answer

Is is possible to change a path's root folder with .htaccess?

I have a website set up with its own root directory in the common configuration: mywebsite.com --> /path/www/mywebsite And them pathnames on mywebsite get naturally mapped to their corresponding subdirectory: mywebsite.com/folder_a/ -->…
Ale Morales
  • 113
  • 3
1
vote
1 answer

ProxyPass and ProxyPassReverse causing 500 error on server

We have the following: WordPress static website at https://www.domain1.com. React/Django Web application at https://www.domain2.com with three main URIs: / /admin /api We would like them to appear like they are the same domain at…
cjones
  • 127
  • 5
1
vote
1 answer

How allow a set of IPs and deny everything else? (.htaccess and apache 2.4)

I need allow internet access from a set of IPs and deny everything else. How can I do that? I tried this: Require all denied Require ip x.x.x.x/xx y.y.y.y/yy this: Require all denied Require ip…
jarh1992
  • 111
  • 1
1
vote
2 answers

ErrorDocument and extension less links not working together

On my website, I have the following code to omit the extension of php pages RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] I also added this code to show custom 404 pages ErrorDocument…
Whip
  • 250
  • 1
  • 2
  • 10
1
vote
1 answer

How to remove ".com" suffix from hostname variable using .htaccess

I'm attempting to create a unique series of redirects on an Apache web server (Server version: Apache/2.2.15). Using .htaccess or additional Apache modules, I need to fully parse requested URLs in order to extract hostnames without the standard .com…
sparecycle
  • 459
  • 1
  • 6
  • 19
1
vote
1 answer

Website root trailing slash auto-removed (issue)

as per title, when I enter my website URL manually (examples at the end of the topic), the trailing slash at the end of the domain being removed automatically. I have SSL redirect forced and Apache ModRewrite enabled in .htaccess and this is the…
simone_meh
  • 15
  • 4
1
vote
1 answer

Apache 2.4 Convert .htaccess and rewrite it to vhost.conf

I am rewriting the Apache 2.4 configuration that I've received from the old development team. I have ~200 lines of similar configuration, and I can not understand on what principle I need to change this code to move it from .htaccess to…
1
vote
1 answer

Apache: Access management via .htaccess not working

For a few hours now, I've been trying to create a working .htaccess file that forbids access to all files with the exception of a few files and folders. But whenever I write Allow from all in my .htaccess file in a direct subdirectory of my root…
levi-jcbs
  • 23
  • 3
1
vote
1 answer

Rewrite Rule for URL with query does not work

I write the following rewrite rule: RewriteCond %{QUERY_STRING} rp=\/knowledgebase\/.* RewriteRule ^\/customer\/index.php /knowledgebase/ [R=301,L] RewriteRule ^\/customer\/knowledgebase\.php$ /knowledgebase/…
alancc
  • 141
  • 12
1
vote
1 answer

Need help understanding .htaccess

Can someone explain what each line means? Options +FollowSymLinks +ExecCGI RewriteEngine On # uncomment the following line, if you are having trouble # getting no_script_name to work #RewriteBase / # we skip all…
PHP
1
vote
1 answer

Redirect French homepage (and only FR home page) to English home page

Using the .htaccess file, I would like to redirect www.example.com/fr/ to www.example.com/ but not other French pages that have the /fr/ root (e.g. www.example.com/fr/page-name) I've tried using Redirect 301 /fr/ https://example.com/ but that…
Samuel
  • 13
  • 2
1
vote
1 answer

.htaccess Remove first php url parameter if second exist

This is my .htaccess code: RewriteCond %{REQUEST_URI} !^/pages/ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))? pages.php?PAGE=$1&LINK=$3 [L] *where $1 = profile and $3 = john-smith This…
Adrian
  • 11
  • 2
1
vote
1 answer

Block a URL and its sub URL using Htaccess

I have a URL http://example.com/web/en/press-release/. How can I block all users access and viewing that page and http://localhost:10004/web/en/press-release/* using .htaccess? I want them only accessible from specific IPs. I did like this but not…
Ben
  • 11
  • 2