bitnami / vms

Bitnami VMs
https://bitnami.com
Other
200 stars 44 forks source link

[Wordpress] Redirect - which file to edit? #1572

Open philippirsl opened 2 weeks ago

philippirsl commented 2 weeks ago

Platform

AWS

bndiagnostic ID know more about bndiagnostic ID

n/a

bndiagnostic output

No response

bndiagnostic was not useful. Could you please tell us why?

Not necessary for now

Describe your issue as much as you can

I have a fresh installation of Wordpress through a Bitnami instance on AWS with Apache.

The other instance was backed up and restored correctly, and the certificate was definitely installed.

The problem I'm facing now is which files should I configure so that I can get the following result, when accessing https://blog.mydomain.com it is redirected to https://mydomain.com/blog

I tried some files without success, and in one case, I was successful, but the page was completely unconfigured and I no longer had access to the wp admin.

gongomgra commented 1 week ago

Hi @philippirsl,

Thanks for using Bitnami. You can find Apache configuration files for WordPress under /opt/bitnami/apache2/conf/vhosts directory. You can add the required configuration there. Remember to restart the Apache service for changes to take effect

sudo /opt/bitnami/ctlscript.sh restart apache
philippirsl commented 1 week ago

Hi @gongomgra

I am using CloudFront and adjusted the wordpress-htaccess.conf file as follows

_<Directory "/opt/bitnami/wordpress/"> RewriteEngine On RewriteBase/ RewriteCond %{HTTPREFERER} !blogMyBlog [NC] RewriteRule ^(.*)$ https://myblog.com/blog$1 [L,R=301]

Em CloudFront, in Origins with a reference of Origin name: my-blog Origin Domain: blog.mydomain.com

And my Origin settings are: blog.mydomain.com HTTPS only, TLS v1.2, In Add custom header - optional, I have it configured header name: referer value blogMyBlog

Alter /opt/bitnami/wordpress/wp-config.php to _define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/blog' ); define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/blog' ); define( 'WP_AUTO_UPDATECORE', 'minor' );

After configuration in the wordpress-htaccess.conf file, at first the blog was redirected, but when I try to put it into production, it goes into a loop with a sequence of mydomain.com/blog/blog/.... and returning a 404 error.

Just to understand that i want to have access to blog.mydomain.com at mydomain.com/blog

jeffrey597doss commented 1 week ago

o redirect https://blog.mydomain.com to https://mydomain.com/blog using a Bitnami WordPress instance on AWS with Apache, modify the Apache configuration. SSH into your instance, edit /opt/bitnami/apache2/conf/httpd.conf, and add a redirection rule under a <VirtualHost *:443> section for blog.mydomain.com. Use:

apache Copy code <VirtualHost *:443> ServerName blog.mydomain.com Redirect permanent / https://mydomain.com/blog/ Save, restart Apache (sudo /opt/bitnami/ctlscript.sh restart apache), and ensure WordPress settings reflect https://mydomain.com/blog. Verify the redirection works as expected in your browser.

Regards, marykayintouch

@gongomgra removed third-party links

gongomgra commented 1 week ago

@philippirsl I think you have to configure the redirects in the vhost.conf and https-vhost.conf files instead of the httaccess.conf. I also think you may be missing the equal (=) string comparison character in your statement. You can find the related Apache docs below

https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond

philippirsl commented 1 week ago

@jeffrey597doss and @gongomgra although the redirects occur, I get the 404 error as nothing is found. Should I move the Wordpress folder to a specific directory or is it not necessary to change the default Wordpress folder?

gongomgra commented 1 week ago

@philippirsl it shouldn't be necessary to move the WordPress installation to any other location (notice that movement may also break other configurations in the installation). The issue should be in Apache+WordPress config and/or CloudFlare

philippirsl commented 1 week ago

@gongomgra thnak you for responde, what would a configuration file for basic redirection look like? I mean, for example from blog.mydomain.com to mydomain.com/test, would you have an example, because even doing it this way I haven't been successful yet. I say that the redirection even occurs, but I can't access any page other than 404.

philippirsl commented 1 week ago

I did a search, and based on this post https://github.com/bitnami/vms/issues/100, I managed to get a certain result, but I still have problems with the return, as it is coming as blog.mydomain.com/blog, I want to remove blog.mydomain.com, leaving only mydomain.com/blog

philippirsl commented 6 days ago

Don't we have a tutorial on this? I'm thinking that the 404 error I'm getting is due to having to modify something in the sql files? Can anyone actually explain to me how it works if I make this change from blog.mydomain.com to mydomain.com/blog? I believe this is something easy to solve, but unfortunately I'm stuck.

gongomgra commented 5 days ago

@philippirsl I don't fully understand your Cloudflare configuration, but I think your redirection rules should be similar to the ones showed in this tutorial for www.domain.com to domain.com but for blog.domain.com instead of www

https://docs.bitnami.com/aws/apps/wordpress/administration/redirect-custom-domains/#add-redirection-rules

Can you also double check your browser is not caching the previous redirections?

philippirsl commented 5 days ago

I don't use CloudFlare but CloudFront. I only explained it because of the scenario, although this does not significantly reflect on the settings

philippirsl commented 5 days ago

@gongomgra

let's go

Let's forget about CloudFront at this point, and just stick to redirection.

In this case, my wordpress-https-vhost.conf file looks like this

<VirtualHost *:443>
 ServerName blog.mydomain.com
 RewriteEngine On
 RewriteRule ^/?(.*)$ https://mydomain.com/blog/$1 [R=301,L]
 SSLEngine on
 SSLCertificateFile "/opt/bitnami/apache/conf/blog.mydomain.com.crt"
 SSLCertificateKeyFile "/opt/bitnami/apache/conf/blog.mydomain.com.key"
</VirtualHost>
<VirtualHost *:443>
 ServerName domain.com
 DocumentRoot /opt/bitnami/wordpress
 Alias ​​/blog /opt/bitnami/wordpress/
 SSLEngine on
 SSLCertificateFile "/opt/bitnami/apache/conf/blog.mydomain.com.crt"
 SSLCertificateKeyFile "/opt/bitnami/apache/conf/blog.mydomain.com.key"
 <Directory "/opt/bitnami/wordpress">
 Options -Indexes +FollowSymLinks -MultiViews
 AllowOverride None
 Require all granted
 # BEGIN WordPress fix for plugins and themes
 RewriteEngine On
 RewriteRule ^bitnami/wordpress(/.*) $1 [L]
 # END WordPress fix for plugins and themes
 # BEGIN WordPress
 RewriteEngine On
 RewriteBase /blog/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /blog/index.php [L]
 # END WordPress
 </Directory>
 Include "/opt/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf"
</VirtualHost>

I can get the redirection to occur, but I get the 404 error.

Remembering that I also edited the wp-config.php file

define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/blog' );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/blog' );

Apparently, something is missing for this redirection to occur correctly....

philippirsl commented 1 day ago

Maybe you're not making me understand.

I need to change a subdomain to a subdirectory. It is possible? my subdomain is blog.mydomain.com and I need it to be available at mydomain.com/blog.

gongomgra commented 20 hours ago

Hi @philippirsl,

I still think your Apache configuration regarding the redirection is not 100% correct, but I'm afraid there isn't much else I can do here. We can only help you with basic questions and links to our documentation or the official site. However, if you require further help, we suggest you find someone in your community or in other specialized forums who can help you review the changes in the Apache's configuration.

philippirsl commented 18 hours ago

Great!!