i have a website at xyz.com and what i am trying to do now is to host a wordpress in a subdirectory of this xyz.com , like xyz.com/blog.
my wordpress homepage is working but admin and wp-login.php is not working because it goes into a redirect loop.
i tried with apache2 and nginx both and also tried every htaccess rules from stackoverflow questions but i am not able to resolve it.
please help !!
Fix the .htaccess
File (for Apache)
Ensure the .htaccess
file in the blog/
subdirectory is correctly configured:
# WordPress standard .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
now restart apache
Fix Nginx Configuration
If you’re using Nginx, ensure your server block is properly configured:
server {
listen 80;
server_name xyz.com;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php;
}
location /blog/ {
index index.php;
try_files $uri $uri/ /blog/index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust PHP version as needed
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
After making changes, restart Nginx: