代码之家  ›  专栏  ›  技术社区  ›  Cinzel

从URL跳过Joomla

  •  1
  • Cinzel  · 技术社区  · 9 年前

    我的网站运行在Joomla上,Joomla安装在 http://example.com/joomla http://example.com (我从根目录访问Joomla文件夹)。我发现将joomla与我网站上的其他文件和文件夹分开很好,但访问者在URL中看到joomla并不重要,因为他们最好只看到URL中与他们在我网站上搜索的内容有更多关系的内容。 所以我想让我们从URL中跳过joomla。 由于Cloudflare,所有URL必须是www URL才能正常工作。

    https://stackoverflow.com/a/35047905/5681573

    我的修改版本:

    .htaccess在根目录中:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} !joomla/
    RewriteRule ^(.*)$ /joomla/$1 [L]
    

    .htjoomla/子目录中的访问权限:

    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    

    在joomla/configuration中。php I set$live_site=” https://example.com “和

    • myserverpath/public\u html/joomla/administrator/logs
    • myserverpath/public\u html/joomla/tmp

    但非www URL存在一个问题:

    还有一个例外是管理员URL,这也是一个问题,因为在使用www URL和非www URL时,它都无法从URL中跳过Joomla:

    • 将$live_站点更改为“”(没有帮助)
    • 将$live_站点更改为' https://www.example.com
    • 将$live_站点更改为' “(没有帮助)
    • 更改joomla/中的RewriteBase。htaccess to RewriteBase/(完全没有变化)

    欢迎提供一些有用的提示或可能的解决方案。提前谢谢。

    由于解决方案答案而编辑:

    关于我在此页面上发布的解决方案答案中的前三行代码:我仅为管理员URL创建了它们:

        RewriteCond %{REQUEST_URI} (.*)administrator$
        RewriteCond %{REQUEST_URI} !/$
        RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
    

    虽然joomla成功地从所有URL中跳过(请参阅答案和解决方案),但对于我来说,问题仍然是为什么需要添加上面所示的尾随斜杠,以解决管理员URL的问题。否则,当您不添加这三行代码时,管理员URL将重定向到joomla/administrator,并在URL中显示joomla。

    1 回复  |  直到 9 年前
        1
  •  0
  •   Cinzel    9 年前

    我很高兴地说,我的问题找到了解决办法。

    对于任何有相同问题的人,以下是解决方案:

    • 在joomla/directory的htaccess中不需要任何rewriterule,只是不要在该htaccess文件中写入rewriterules
    • # keep codes on top !!!
      RewriteEngine On
      RewriteCond %{REQUEST_URI} (.*)administrator$
      RewriteCond %{REQUEST_URI} !/$
      RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
      RewriteCond %{THE_REQUEST} joomla/
      RewriteRule ^joomla/(.*) https://www.%{HTTP_HOST}/$1 [R=301,L]
      RewriteCond %{REQUEST_URI} !joomla/
      RewriteRule ^(.*)$ /joomla/$1 [L]
      

    感谢伟大的SiteGround支持团队(我的提供商),因为他们能够找到解决方案,使一切按预期工作。