I have my site running in GCP, I need to edit the .htaccess file to create a redirect that redirects www to non www. How do I configure it?. I don't see .htaccess file in my website, I used a file manager plugin to access wordpress core files.
I read somewhere bitnami has htaccess configured differently,.How do I create the redirect?
BTW, my httpd-vhosts.conf file has the following lines of code,.
<VirtualHost *:80>
ServerName wordpress.example.com
ServerAlias www.wordpress.example.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
ServerName wordpress.example.com
ServerAlias www.wordpress.example.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/server.key"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
It literally has example.com, not mydomain.com, should I be worried?
There are many ways to implement redirection. A simple method is to modify your apache conf file. Replace example.com with your domain name.
<VirtualHost *:80>
ServerName example.com
# Redirect everything arriving on HTTP to HTTPS
Redirect "/" "https://example.com/"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
# Redirect anything that is not "example.com"
<If "%{HTTP_HOST} != 'example.com'">
Redirect "/" "https://example.com/"
</If>
</VirtualHost>
Redirecting and Remapping with mod_rewrite
Read this link for common use cases to avoid:
You should modify ServerName
to represent your server's domain name. This should match what you configure in WordPress Settings for WordPress Address
and Site Address
.
If you are using bitnami wordpress that you could configure directly in wordpress cause the only .htaccess that has wordpress is in
/opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/akismet/.htaccess
I suggest you change the name site, here is the link of wordpress to do it. Also consider in your dns records have the records
wordpressexample.com A external IP www.wordpressexample.com CNAME wordpressexample.com
This is in order to enable me to get access to your website from both links.
Since you're not asking about why my WordPress website not showing
, I assume that your WordPress website just working fine, so you can let the ServerName as is.
Furthermore, refer to the document of Apache HTTP Server
Due to the fact that the virtual host with ServerName www.example.com is first in the configuration file, it has the highest priority and can be seen as the default or primary server.
That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first .
Even though the ServerName might not match your real domain, the first VirtualHost on *:80 will be used.
So if your WordPress website is working, I'll recommend that just keep it example.com.
For the redirect setting, refer to the article on Bitnami
You can try to use SSH and use one of text editors edit the /opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf
file:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=permanent,L]
ServerName wordpress.example.com
ServerAlias www.wordpress.example.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1$1 [R=permanent,L]
ServerName wordpress.example.com
ServerAlias www.wordpress.example.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/server.key"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
You will need to restart the Apache HTTP Web Server in order to reload the setting file.
$sudo /opt/bitnami/ctlscript.sh restart apache
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.