从 URL 跳过 Joomla [英] Skip Joomla from the URL

查看:18
本文介绍了从 URL 跳过 Joomla的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站在 Joomla 上运行,它安装在 http://example.com/joomla,但是我的 URL 仍然是 http://example.com(我从根访问 Joomla 文件夹).我发现将 joomla 与我网站上的其他文件和文件夹分开是很好的,但与访问者在 URL 中看到 joomla 无关,因为他们最好只看到 URL 中与他们在我的网站上搜索的内容更相关的内容地点.所以我想让我们从 URL 中跳过 joomla.而且由于 Cloudflare,所有 URL 都必须是 www-URL 才能正常工作.

由于以下解决方案,我能够实现这一目标:

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

我的修改版本:

.htaccess 在根目录:

RewriteEngine onRewriteCond %{THE_REQUEST} !joomla/重写规则 ^(.*)$/joomla/$1 [L]

.htaccess 在 joomla/子目录中:

RewriteCond %{HTTP_HOST} !^$RewriteCond %{HTTP_HOST} !^www.[NC]重写规则 ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

在我的解决方案中包括从非 www URL 到 www-URL 以及从 http 到 https 的重定向.

在 joomla/configuration.php 我设置 $live_site = "https://example.com" 和将 tmp 和 log 文件夹更改为:

  • myserverpath/public_html/joomla/administrator/logs
  • myserverpath/public_html/joomla/tmp

一切看起来都很好.现在,当我测试它时,结果如下:

但非 www 网址存在问题:

当非 www URL 重定向到 www-URL 时,Joomla 不会从 URL 中跳过.所有其他以 www 开头的链接都正确显示,URL 中没有joomla".无论您是直接输入地址,还是通过网站上的链接或按钮到达那里:joomla 都会进一步从任何 www-URL 中跳过.就在那一刻,一个非 www 的 URL 被重定向到一个无法工作的 www-URL,并且 URL 中出现了joomla"这个词.

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

我搜索了好几个小时都没有结果.

我试图解决的一些问题:

  • 将 $live_site 更改为 ''(无济于事)
  • 将 $live_site 更改为https://www.example.com"(无帮助)
  • 将 $live_site 更改为https://example.com"(没有帮助)
  • 将 joomla/.htaccess 中的 RewriteBase 更改为 RewriteBase/(根本没有更改)
  • 将 joomla/.htaccess 中的 RewriteBase 更改为 RewriteBase/joomla/(完全没有变化)

非常欢迎一些有用的提示或可能的解决方案.提前致谢.

编辑因为解决方案答案:

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

<块引用>

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

尽管 joomla 已成功从所有 URL 中跳过(请参阅解决方案的答案),但对我而言,问题仍然是为什么需要添加如上所示的尾部斜杠,以便为管理 URL 解决该问题.否则,当您不添加这三行代码时,管理 URL 将重定向到 joomla/administrator 并在 URL 中显示 joomla.这与定义设置有什么关系吗?...谁知道...

解决方案

很高兴我的问题找到了解决方案.

对于任何有同样问题的人,这里是解决方案:

  • joomla/目录的 htaccess 中不需要任何 rewriterule,只是不要在该 htaccess 文件中写入 rewriterule
  • 在根 htaccess 文件中注意添加重写器的位置:您应该将它们放在 htaccess 文件的顶部.这些代码可以解决问题:

    # 把代码放在最前面!!!重写引擎开启RewriteCond %{REQUEST_URI} (.*)administrator$RewriteCond %{REQUEST_URI} !/$重写规则 ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/[L,R=301]RewriteCond %{HTTP_HOST} !^www.[NC]重写规则 ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]RewriteCond %{THE_REQUEST} joomla/重写规则 ^joomla/(.*) https://www.%{HTTP_HOST}/$1 [R=301,L]RewriteCond %{REQUEST_URI} !joomla/重写规则 ^(.*)$/joomla/$1 [L]

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

My site runs on Joomla, which is installed in http://example.com/joomla, but my URL is still http://example.com (I access the Joomla folder from the root). I find it good to have joomla separated from other files and folders on my site, but irrelevant that visitors see joomla in the URL, since it's better they see only things in the URL that has more to do with what they are searching for on my site. So I thought let's skip joomla from the URL. And because of Cloudflare all URLs must be www-URLs in order to work properly.

I was able to achieve this thanks to the below solution:

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

My modified version:

.htaccess in the root:

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

.htaccess in the joomla/ subdirectory:

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

In my solution is included redirection from non-www URLS to www-URLs and from http to https.

In joomla/configuration.php I set $live_site = "https://example.com" and changed the tmp and log-folders to:

  • myserverpath/public_html/joomla/administrator/logs
  • myserverpath/public_html/joomla/tmp

Everything looks fine. Now when I test it these are the results:

But there is a problem with non-www URLs:

Joomla is not skipped from the URL when non-www URLs are redirected to www-URLs. All other links that begin with www are correctly showing without 'joomla' in the URL. No matter if you type the address directly or if you arrive there via a link or button on the website: joomla is further always skipped from any www-URL. It's just that moment that a non-www URL is redirected to a www-URL that it's not working and the word 'joomla' is appearing in the URL.

And also 1 exception is the admin URL, which also is a problem, unique because it's failing to skip Joomla from the URL both when used the www-URL as well as the non-www-URL:

I searched hours and hours without result.

Some things I tried to solve this:

  • changing $live_site to '' (not helping)
  • changing $live_site to 'https://www.example.com' (not helping)
  • changing $live_site to 'https://example.com' (not helping)
  • changing RewriteBase in joomla/.htaccess to RewriteBase / (no change at all)
  • changing RewriteBase in joomla/.htaccess to RewriteBase /joomla/ (no change at all)

Some useful hints or possible solutions are very welcome. Thanks in advance.

Edit because of the solution answer:

About the first three lines of codes in the solution answer that I posted on this page: I created them only for the admin URL:

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

Although joomla is skipped from all URLs successfully (see answer with solution), for me the question remains why it's needed to add the trailing slash as you see above, in order to solve it for the admin URL. Otherwise, when you don't add these three lines of codes the admin URL will redirect to joomla/administrator and will show joomla in the URL. Does this have anything to do with the defines settings?... Who knows...

解决方案

I'm glad to say the solution for my issue is found.

For anyone who has the same problem, here is the solution:

  • no need to have any rewriterule in the htaccess of the joomla/ directory, just don't write rewriterules in that htaccess file
  • in the root htaccess file take care of where you add the rewriterules: you should put them on TOP of the htaccess file. These codes will do the trick:

    # 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]
    

Thanks and credits to the great SiteGround support team (my provider), as they were able to find the solution to make everything work as expected.

这篇关于从 URL 跳过 Joomla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆