1

I have done a fresh wordpress installation from a subdirectory. I've followed the official wordpress guide to give wordpress it's own directory, but now I have a login loop problem, I'm not able to login to the dashboard and every attempts will redirect me to the login sreen. How I can fix this?

I have this code inside my .htaccess root file

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /web/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ web/index.php [L] 
</IfModule>

And this is the .htaccess file inside the directory where wordpress is installed


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
0

...this is the .htaccess file inside the directory where wordpress is installed

That is certainly incorrect as it's sending requests back to the root. You can remove the RewriteBase directive and remove the slash prefix on the RewriteRule substitution string, ie /index.php should be index.php.

For example:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# END WordPress

I've "commented out" the RewriteBase directive, rather than removing it completely.

By removing the slash prefix on the RewriteRule substitution then it is seen as relative to the current directory. ie. Relative to /web, so this rewrites the request to /web/index.php, not /index.php. (The RewriteBase directive would override this.)

| improve this answer | |
  • Ok, I missed this part but it's not written inside the wordpress guide. I was editing the file to force the use of https on the whole site. I was thinking that the error was there. I will test and let you know. Thanks! – sialfa May 5 at 16:12
  • I've tested, but it will continue to give me the login loop issue :( ! I think that this is because of this line to force https RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]? – sialfa May 5 at 16:15
  • Although that doesn't really have anything to do with the subdirectory / login? That will result a redirect loop if you are using a front-end proxy to manage your SSL eg. Cloudflare Flexible SSL. (?) – MrWhite May 5 at 16:46
  • What exactly is the redirect loop you are seeing? From / to URLs? I would certainly make sure your browser cache is cleared, since any erroneous 301 redirects are cached persistently by the browser. Do you have files outside of the /web subdirectory that need to be accessible? If not, then your root .htaccess file can be greatly simplified. As it is, the root .htaccess file is not strictly correct (although unlikely to be the cause of this current issue). – MrWhite May 5 at 17:28
  • for redirect loop I mean that after inserting the credentials I will not redirected to the dashboard but I will see again the login page. In the root there is only the folde where wordpress files are stored, nothing else. – sialfa May 5 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.