Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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,332
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
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,112
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.6k
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
  • 167k
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.9k
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,419
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.3k
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
  • 100k
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
  • 100k
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
  • 18.2k
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
  • 18.2k
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
  • 18.2k
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
  • 167k
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
  • 100k
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

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,728
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,876
2 votes
Accepted

How to fix my Rewriterule in .htaccess to transparently redirect any domain alias?

This worked: I had to use the ?q= inside the last rewriterule like this: RewriteRule ^/?$ ?q=landingpage/%1-%2 [L]
Yuri's user avatar
  • 618
2 votes

Create a general rewrite rule in .htaccess

Rewrites this code for your problem in .htaccess. The code will work for any string in between reading_ and .html RewriteEngine On RewriteRule ^reading_(.*)\.html$ http://www.server.com/reading/$...
Ashish Deynap's user avatar
2 votes
Accepted

Where is the .htaccess file?

If you download Drupal from here, there is the .htaccess file in main directory. How do you downloaded Drupal source code?
arrubiu's user avatar
  • 3,222
2 votes

Where is the .htaccess file?

I executed the command you quoted, and I got the following files. (I executed ls -alF in the directory where Drupal 8.3.0 was copied from Drush.) -rw-rw-rw- 1 kiamlaluno kiamlaluno 262 Apr 6 02:...
apaderno's user avatar
  • 97.5k
2 votes

Two sites on the same server don't work

As said previously, check your HTACCESS on both sites, and your apache virtual host. In theory, you can imbricate websites... But it's not recommended and not easily maintainable. But the simpler and ...
JudaPriest's user avatar

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