I would really appreciate some help in rewriting something. I have moved a site to a sub domain and now the links to that site are not working.
The link before was:
https://www.domainname.com/folder/folder/folder/folder/show?elem=icon_file9393
The new link it needs to redirect to with added sub domain is:
https://www.subdomain.domainname.com/folder/folder/folder/folder/show?elem=icon_file9393
the folder names are dynamic show?elem= will always be there but the icon_file9393 is dynamic
Any help would be much appreciated
This is what I am currently trying in /opt/bitnami/apache/conf/vhost/wordpress-https-vhost.conf
<VirtualHost 127.0.0.1:443 _default_:443>
ServerName www.example.com
ServerAlias *
SSLEngine on
SSLCertificateFile “###########”
SSLCertificateKeyFile “##########”
DocumentRoot /opt/bitnami/wordpress
# BEGIN: Configuration for letsencrypt
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
# END: Configuration for letsencrypt
# BEGIN: Support domain renewal when using mod_proxy without Location
<IfModule mod_proxy.c>
ProxyPass /.well-known !
</IfModule>
# END: Support domain renewal when using mod_proxy without Location
# BEGIN: Enable non-www to www redirection
RewriteEngine On
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)elem=[^&]+(&|$) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?domainnmae\.com$ [NC]
RewriteRule ^[^/]+/[^/]+/[^/]+/[^/]+/show/?$ https://www.subdomain.domainname.com%{REQUEST_URI} [R=301,L,NC,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^localhost
RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
RewriteCond %{REQUEST_URI} !^/\.well-known
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
# END: Enable non-www to www redirection
<Directory "/opt/bitnami/wordpress">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Require all granted
# BEGIN WordPress fix for plugins and themes
# Certain WordPress plugins and themes do not properly link to PHP files because of symbolic links
# https://github.com/bitnami/bitnami-docker-wordpress-nginx/issues/43
RewriteEngine On
RewriteRule ^bitnami/wordpress(/.*) $1 [L]
# END WordPress fix for plugins and themes
# BEGIN WordPress
# https://wordpress.org/support/article/htaccess/#basic-wp
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</Directory>
Include "/opt/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf"
# BEGIN: Support domain renewal when using mod_proxy within Location
<Location /.well-known>
<IfModule mod_proxy.c>
ProxyPass !
</IfModule>
</Location>
# END: Support domain renewal when using mod_proxy within Location
</VirtualHost>
This is the /opt/bitnami/apache/conf/vhost/htaccesss/wordpress-htaccess.conf:
<Directory "/opt/bitnami/wordpress/wp-content/plugins/akismet">
# Only allow direct access to specific Web-available files.
# Apache 2.2
<IfModule !mod_authz_core.c>
Order Deny,Allow
Deny from all
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
# Akismet CSS and JS
<FilesMatch "^(form\.js|akismet(-frontend|-admin)?\.js|akismet(-admin)?(-rtl)?\.css|inter\.css)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>
# Akismet images
<FilesMatch "^(logo-(a|full)-2x\.png|akismet-refresh-logo\.svg|akismet-refresh-logo@2x\.png|arrow-left\.svg)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>
</Directory>
You may use this redirect rule in root .htaccess of domain.com
:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)elem=[^&]+(&|$) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?domainname\.com$ [NC]
RewriteRule ^/?[^/]+/[^/]+/[^/]+/[^/]+/show/?$ https://www.subdomain.domainname.com%{REQUEST_URI} [R=301,L,NC,NE]
Query string will automatically be forwarded to the new redirect URL.