Why does mod_rewrite redirect to /index.php/index.php/index.php etc

人盡茶涼 提交于 2021-01-28 12:27:57

问题


I want every subdomain to act as a folder, so basicly:

projects.dev -> /
test.projects.dev -> /test
amazing-project.projects.dev -> /amazing-project

And I have this code in my Virtualhost file:

<VirtualHost *:80>
  ServerName projects.dev
  DocumentRoot "D:/xampp/htdocs/projects"
  ServerAlias *.projects.dev
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^(.*)\.projects\.dev
  RewriteRule ^/(.*)$ "D:/xampp/htdocs/projects/%1/$1" [L,R=301]
</VirtualHost>

However when i go to "designs.projects.dev" it gets redirected to "designs.projects.dev/index.php/index.php/index.php/index.php/" (the /index.php continues for a while).

Does anyone know why this happens?

Thanks.


回答1:


You can use

<VirtualHost *:80>
  ServerName projects.dev
  ServerAlias *.projects.dev

  DocumentRoot "D:/xampp/htdocs/projects"

  RewriteEngine on

  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.projects\.dev$ [NC]
  RewriteRule ^ /%1%{REQUEST_URI} [L]

</VirtualHost>


来源:https://stackoverflow.com/questions/46872827/why-does-mod-rewrite-redirect-to-index-php-index-php-index-php-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!