Apache 如何配置重写规则,以便即使URL中使用别名,请求也将路由到服务器名称

Apache 如何配置重写规则,以便即使URL中使用别名,请求也将路由到服务器名称,apache,.htaccess,redirect,mod-rewrite,vhosts,Apache,.htaccess,Redirect,Mod Rewrite,Vhosts,我们有一个包含以下内容的虚拟主机文件 NameVirtualHost *:8888 <VirtualHost *:8888> ServerName example.domain.com ServerAlias example DocumentRoot /opt/weblogic/product/virtualhosts/example.domain.com/htdocs ErrorLog /opt/weblogic/pr

我们有一个包含以下内容的虚拟主机文件

    NameVirtualHost *:8888
    <VirtualHost *:8888>
      ServerName example.domain.com
      ServerAlias example
      DocumentRoot /opt/weblogic/product/virtualhosts/example.domain.com/htdocs
      ErrorLog /opt/weblogic/product/virtualhosts/example.domain.com/logs/error_log
      RewriteEngine On
      #RewriteRule  ^/?$ %{REQUEST_URI}/StartPage [R,L]
      RewriteOptions Inherit
      DirectoryIndex index.html startpage.jsp
      <Directory />
        Require all granted
      </Directory>
    </VirtualHost>
NameVirtualHost*:8888
ServerName example.domain.com
服务器别名示例
DocumentRoot/opt/weblogic/product/virtualhosts/example.domain.com/htdocs
ErrorLog/opt/weblogic/product/virtualhosts/example.domain.com/logs/error\u log
重新启动发动机
#重写规则^/?$%{REQUEST_URI}/StartPage[R,L]
重写选项继承
DirectoryIndex.html startpage.jsp
要求所有授权
我们可以使用服务器名和别名访问应用程序

  • 扩展到
  • http://example 扩展到http://example/StartPage/startpage.jsp
  • 现在,当我们使用下面的服务器别名时,需要将url重定向到服务器名称

    http://example 扩展到


    有人能帮我修改vhost文件使之生效吗。

    这可能就是您想要的:

    RewriteCond %{HTTP_HOST} ^example$
    RewriteRule ^ https://example.domain.com%{REQUEST_URI} [R=301,QSA,END]
    
    规则必须立即遵循符合条件的行。并且重定向应该在其他重定向之前完成

    一开始使用302重定向是一个好主意,只有当您确定一切都按预期工作时,才将其更改为301重定向

    如果您不希望保留所请求URL的路径,而是始终重定向到固定路径前缀,则可以:

    RewriteCond %{HTTP_HOST} ^example$
    RewriteRule ^ https://example.domain.com/StartPage [R=301,QSA,END]