【问题标题】:Apache rewrite rule for removing part of the directory from the url用于从 url 中删除部分目录的 Apache 重写规则
【发布时间】:2020-07-12 13:36:50
【问题描述】:

我使用 apache 设置了以下测试站点,并从以下位置提供服务 /htdocs/www/*

https://local.sweetcar.com/www/mycompany/
https://local.sweetcar.com/www/sweetcar/

我想配置一个 apache 重写来提供以下网址

https://local.mycompany.com/
https://local.sweetcar.com/

因此 www/mycompany/www/sweetcar/ 已从 url 中删除,而其他所有内容都被保留

这是我尝试过的,但没有成功:

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

【问题讨论】:

  • local.mycompany.com 是否有类似local.sweetcar.comVirtualHost 条目?
  • 是的,两个网站都使用上述网址

标签: apache .htaccess url-rewriting apache2


【解决方案1】:

您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{HTTP_HOST} ^local\.([^.]+)\. [NC]
RewriteRule !^www/ www/%1%{REQUEST_URI} [L,NC]

RewriteRule ^index\.php$ - [L]

【讨论】:

  • 感谢您的回复。我将 .htaccess 放入 /htdocs 并收到 500 错误,有什么想法吗?
  • 你能检查一下你的 Apache error.log 看看是什么原因
  • Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
  • 获取相同的 500 错误和错误到 apache 日志。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-08
  • 2013-06-09
  • 2018-01-13
  • 1970-01-01
  • 2015-08-04
  • 2015-08-03
  • 1970-01-01
相关资源
最近更新 更多