【问题标题】:Where should I add custom redirects in Joomla?我应该在 Joomla 的哪里添加自定义重定向?
【发布时间】:2015-12-30 09:40:07
【问题描述】:

在哪里添加重定向?

基于此页面: http://dvlancer.com/67-redirect-pages-with-html-suffix.html

当关闭 html 后缀时,我应该使用这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

只是将 .htaccess 放在上面(在 public_html 文件夹中)没有任何影响:

应该把它放在 htaccess.txt 中吗?这似乎是一个应该包含自定义内容的部分?

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
## End - Custom redirects

【问题讨论】:

  • mod_rewrite 开启了吗?
  • @hjpotter92 在htaccess中关闭,但在.htaccess.txt中开启

标签: apache .htaccess mod-rewrite joomla url-redirection


【解决方案1】:

mod_rewrite 不能按位置关闭。您可以从 apache 的服务器设置中启用/加载重写模块。它通常存储在/etc/apache2/conf.d/ 中,文件名为httpd.confapache2.conf

在文件中搜索以下文本:

LoadModule rewrite_module modules/mod_rewrite.so

如果它被评论(前面是#);取消注释,重启服务器。


重写规则需要放在一个名为.htaccess的文件中。文件htaccess.txt 用于为新开发人员提供帮助,并且不会被服务器处理。此外,在评估任何其他重写功能之前,您需要有 RewriteEngine On 声明。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

【讨论】:

  • 好吧,这很奇怪。我更改了 htaccess.txt 中的一些内容,之后服务器无法工作......这就是我问这个问题的原因。不过非常感谢!我试图恢复文件 .htaccess 和 .htaccess.txt 但服务器仍然无法工作):我没有任何访问 apache-configuration 等的权限,但我不明白出了什么问题......
猜你喜欢
  • 2020-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-13
  • 2017-01-20
  • 2017-03-30
  • 1970-01-01
相关资源
最近更新 更多