Bitnami Apache 重写重写条件和规则

问题描述 投票:0回答:1

我真的很感激在重写一些东西时得到一些帮助。 我已将一个网站移至子域,但现在该网站的链接不起作用。

之前的链接是:

https://www.domainname.com/folder/folder/folder/folder/show?elem=icon_file9393

添加子域后需要重定向到的新链接是:

https://www.subdomain.domainname.com/folder/folder/folder/folder/show?elem=icon_file9393

文件夹名称是动态的 show?elem= 将始终存在,但 icon_file9393 是动态的

任何帮助将不胜感激

这就是我目前在 /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\.)?inspire\.education$ [NC]
  RewriteRule ^[^/]+/[^/]+/[^/]+/[^/]+/show/?$  https://www.explore.inspire.education%{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>

这是 /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>
regex apache mod-rewrite url-rewriting
1个回答
0
投票

您可以在

domain.com
的root .htaccess中使用此重定向规则:

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]

查询字符串将自动转发到新的重定向 URL。

© www.soinside.com 2019 - 2024. All rights reserved.