11 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 ...
rjkunde's user avatar
  • 211
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 ...
mikeytown2's user avatar
  • 8,272
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 ...
hotwebmatter's user avatar
  • 2,102
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: ...
Stefanos Petrakis's 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, ...
tenken's user avatar
  • 18.4k
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 ...
neotohin's user avatar
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 ...
Weston Wedding's user avatar
5 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: ...
Gerald Melendez's 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 ...
Jaypan's user avatar
  • 17.3k
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 "/...
AjitS's user avatar
  • 10.9k
4 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 ...
kufeiko's user avatar
  • 425
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 ...
Clive's user avatar
  • 166k
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 ...
Neograph734's user avatar
  • 8,379
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 ...
Kevin's user avatar
  • 27.7k
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 ...
No Sssweat's user avatar
  • 31.1k
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 ...
4uk4's user avatar
  • 98.1k
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. ...
4uk4's user avatar
  • 98.1k
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/, #...
leymannx's user avatar
  • 17.8k
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 ...
leymannx's user avatar
  • 17.8k
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 ...
Eugene Bocharov's 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-...
leymannx's user avatar
  • 17.8k
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 ...
Clive's user avatar
  • 166k
3 votes
Accepted

Website doesn't load properly from htdocs/web

This is very limited shared-hosting, no control panel and no way to edit apache's configs, only .htacess files accessible in htdocs Look for a new hosting company, until then you can use the legacy ...
4uk4's user avatar
  • 98.1k
2 votes
Accepted

Rdirected site folder doesn't work

Just add a rewriteBase to your .htaccess file RewriteBase /subdirectory Note that this goes into the .htaccess file in the “subdirectory”, not your website root .htaccess file!
Sohail's user avatar
  • 1,544
2 votes
Accepted

htaccess non www to www redirect is not working properly

Your problem is more than likely that you are placing the rewrite rules after the catch-all rule. Try restoring the stock .htaccess, and uncommenting lines 92-94, so that it reads # To redirect all ...
mpdonadio's user avatar
  • 38k
2 votes
Accepted

With out www in url redirecting to home page

The .htaccess file you show above is not doing that redirect. You must have some code in PHP that is causing example.com/abc to redirect to example.com. I would look through your code for 'www' to see ...
Michael Cooper's user avatar
2 votes
Accepted

Only front page works

I believe the problem was due to the location of my .htaccess file. (The main problem was the Clean URLs.) My original location was /var/www/drupal/sites/default/files; after, I moved it to /var/www/...
Kemal Tezer Dilsiz's user avatar
2 votes
Accepted

Special code for .htaccess and robots.txt files

It looks like the most important bit they want you to put in .htaccess is this: SetEnvIfNoCase User-Agent "^SemrushBot" bad_user SetEnvIfNoCase User-Agent "^DotBot" bad_user SetEnvIfNoCase User-Agent ...
Beebee's user avatar
  • 6,851
2 votes

How to check if Drupal user is logged in via htaccess?

Drupal does store the session value in the cookie variable after the user is logged in. However, the name of this cookie is not fixed. It is basically a string that comes from the value returned by ...
AjitS's user avatar
  • 10.9k
2 votes

Problem with SSL certificate

There are some known issues with Drupal 7.x in some server configurations particularly around PHP 5.6 and OpenSSL 0.9x due to changes in how PHP verifies SSL certificates. Acquia has some notes about ...
acrosman's user avatar
  • 2,718

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