38 votes

How do I simply make the whole site use a secure connection?

If you want to redirect all of your pages to be forced to use SSL then add this to your .htaccess file. # Redirect to HTTPS RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-Proto} !https ...
user avatar
  • 407
10 votes

redirect whole site to HTTPS

RewriteCond %{HTTPS} !=on # This checks to make sure the connection is not already HTTPS RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # This rule will redirect users from their original ...
user avatar
  • 201
7 votes
Accepted

How to modify .htaccess to serve brotli compressed static assets over gziped ones?

Give this a try # Rules to correctly serve gzip compressed CSS and JS files. # Requires both mod_rewrite and mod_headers to be enabled. <IfModule mod_headers.c> # Serve brotli compressed CSS ...
user avatar
  • 8,242
6 votes

How do I make ugly URLs such as "/index.php?main_page=about_us"?

My advice would be to keep Drupal's URL handling as is and simply configure a set of redirects with code 301 in your .htaccess. That way your URLs will maintain their google ranking. A useful quote: ...
user avatar
6 votes

D8 doesn't create .htaccess for private file system path

This is a better .htaccess to use: # Turn off all options we don't need. Options -Indexes -ExecCGI -Includes -MultiViews # Set the catch-all handler to prevent scripts from being executed. SetHandler ...
user avatar
  • 1,950
5 votes
Accepted

Purpose of the .htaccess files in the Drupal files directory?

The first .htaccess file in the root directory is for routing and to override any PHP related settings. The second .htaccess file under sites/default/files is for security purpose, to avoid any file ...
user avatar
5 votes

.htaccess problem for Drupal

This is a known issue, see: https://www.drupal.org/node/1269780 regarding a longterm resolution. In general it looks like going forward +FollowSymLinks should be replaced with +SymLinksIfOwnerMatch, ...
user avatar
  • 18.3k
5 votes
Accepted

Some images are not displayed in IE

I'm inclined to believe this is a MIME type (or Content Type) configuration issue on the server because the "X-Content-Type-Options nosniff" would bypass this kind of problem. That header is telling ...
user avatar
5 votes
Accepted

How are clean URLs with 200 response codes being managed without doing a RewriteMap?

The Apache mod rewrite module is used. /some/path is rewritten internally by Apache to index.php?q=some/path [Credit: mpdonadio]. index.php bootstraps Drupal. Drupal determines if it is able to ...
user avatar
  • 15.1k
4 votes
Accepted

Clean URLs with multi-site only with suffixes / sub-folders

think you will require a separate virtualhost entry for each of the sub-sites. That should direct visitors to the correct location and negate any need for redirection. At the moment you're using ...
user avatar
  • 4,053
4 votes

What is good way to hide update.php file?

You can add the following line: RewriteRule ^update.php$ - [R=404,NC,L] to your .htaccess file so the web server returns a 404 rather than bootstrapping Drupal to show access denied.
user avatar
4 votes

My server ignores the .htaccess file

This generally happens when your web server does not have access to make the overrides to your webroot. Check if your httpd.conf file has something of the following format <Directory "/...
user avatar
  • 10.8k
4 votes

How to prevent executing .php files in sites/default/files directory for nginx+php7.0-fpm?

This is what works for nginx and only targets files directory: location ~ /files/.*\.php$ { return 403; } This is more generic and wont let any php file in a directory execute directly: ...
user avatar
3 votes
Accepted

Why is my .htaccess not working when uploaded to a Pantheon server?

Because Pantheon servers use Nginx, and they don't enable .htaccess support. You should contact them directly to discuss your options (if you're lucky and/or have a high enough subscription they'll ...
user avatar
  • 164k
3 votes
Accepted

Why are URLs with non-existing subdomains not triggering an error 404?

While you have stated that hosting is the same for both your sites it is most probably that this is either a server configuration issue or a DNS configuration issue rather than a Drupal setting issue. ...
user avatar
3 votes

Clean URL's not respected on local

It may be that your Apache vhost and/or .htaccess need updating. Yosemite uses Apache 2.4, which replaces some access control statements used in 2.2 and prior. 'Allow from all' becomes 'Require all ...
user avatar
  • 2,224
3 votes
Accepted

redirect whole site to HTTPS

You might be interested in the htaccess module: Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings. Drupal tries to provide a one size fits all ...
user avatar
  • 8,219
3 votes

"You don't have permission to access / on this server"

I can't imagine Drupal 8 is supposed to have this done on every installation. You're right, it only needs to be done in .htaccess where altering the web server config isn't an option (think shared ...
user avatar
  • 164k
3 votes

how to stop annoymous users to login in drupal

There is the restrict by IP module, which can solve the use-case pretty fast. For the second part, depending on if you are in 7 or 8, you would want to write code to handle a request to either of the ...
user avatar
  • 26.8k
3 votes
Accepted

After migration, impossible to logging from the remote server, error 'You are not authorized to access this page"

According to kingfisher64 in "Access denied" "you are not authorized to access this page" error ??? Just in case somebody stumbles over this issue the solution for me was in settings.php. I had ...
user avatar
  • 29.7k
3 votes

Create a general rewrite rule in .htaccess

I think your rewrite collides with the other rewrites in drupal standard .htaccess. Try a redirect. The redirect will be executed right away and the rest of .htaccess will no longer be processed. And ...
user avatar
  • 89.4k
3 votes
Accepted

Why are there .htaccess and php files in ./sites/default/php/twig

The PHP files are compiled Twig templates and the .htaccess file protects them from public access. You can switch off the caching of compiled twig templates by setting this service parameter to FALSE. ...
user avatar
  • 89.4k
3 votes

Two sites on the same server don't work

Check both site's .htaccess files and find the lines where it says RewriteBase etc. Your first site's .htaccess needs: # If your site is running in a VirtualDocumentRoot at http://example.com/, #...
user avatar
  • 16.1k
3 votes
Accepted

Getting error 'Redirects to external URLs are not allowed by default'

If you still haven't figured this out, check this comment on d.o: https://www.drupal.org/project/drupal/issues/2612160#comment-11767977 It suggests a workaround by removing the subdir from the script ...
user avatar
  • 405
3 votes
Accepted

Google Page Speed Insights recommends Leverage browser caching

As these files ain't located on your server you can't do anything about it except wondering why Google Page Speed isn't smart enough to distinguish between on-site resources and external resources. Or ...
user avatar
  • 16.1k
3 votes

How do I redirect a domain but keep the URL structure?

Your second variant is close to the goal. But it needs some edits. Firstly, you should escape all dots in RewriteCond, so it will be RewriteCond %{HTTP_HOST} ^example\.co\.uk$ [NC] Secondly you need ...
user avatar
3 votes
Accepted

Patching docroot htaccess: file not found

Look your patch already has the path to web/ in it: --- a/web/.htaccess +++ b/web/.htaccess Just remove the cd web && and adjust the path to the patch accordingly. "post-drupal-scaffold-...
user avatar
  • 16.1k
3 votes

How to restrict access to specific php file to only athenticated users

.htaccess won't help with this; Apache doesn't know what an authenticated Drupal user is, and there's no easy way to grant it that knowledge. Fortunately there's a much better option: Create a route ...
user avatar
  • 164k
2 votes
Accepted

RewriteRule fails if called after line 112 of .htaccess

Just put it above line 112. The reason it doesn't work below that is line 117: RewriteRule ^ index.php [L] that [L] means that if the conditions above it match and that rule is applied no further ...
user avatar
2 votes

How can I make special non-Drupal URLs without file extensions?

If the file exists serve it. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.html -s RewriteRule .* %{REQUEST_URI}\.html [L,T=text/html] You'll need to put it above this inside your .htaccess file. ...
user avatar
  • 8,242

Only top scored, non community-wiki answers of a minimum length are eligible