V
V
Vapaamies2015-06-17 15:58:07
Apache HTTP Server
Vapaamies, 2015-06-17 15:58:07

How to get rid of looping in RewriteRule?

Two virtual domains look at one htdocs. At the root of the hosting, I created directories for them htdocs/forumand htdocs/media. Next to them is this htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} =forum.cantorsys.com [NC]
RewriteRule ^ /forum%{REQUEST_URI} [QSA,L]

RewriteCond %{HTTP_HOST} =media.cantorsys.com [NC]
RewriteRule ^ /media%{REQUEST_URI} [QSA,L]

#RewriteRule ^/(.*)/?(.*)? http://$1.cantorsys.com/$2 [QSA,R=301]

The last redirect had to be commented out because it doesn't work as expected:
  • I would like the view URLs to be http://forum.cantorsys.com/forum/userlist.phpredirected to http://forum.cantorsys.com/userlist.php, that is, to be removed /forumfrom the path and the new path to be in the address bar of the browser.
  • Now http://media.cantorsys.com/forum/userlist.phpit redirects normally, but http://forum.cantorsys.com/forumcauses a loop.

I can not understand the logic of Apache. What, you can not redirect to another path in your domain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ShamblerR, 2015-06-17
@ShamblerR

RewriteCond %{REQUEST_URI} ^/forum/(.*)$ [QSA,L,NC]
RewriteRule ^(.*)$ http:/forum.cantorsys.com/%1 [R=301,L]

Where %1 is what is in the brackets in RewriteCond
If you need a bracket from the RewriteRule, then there is already $1
And you have a cycle because %{REQUEST_URI} contains your forum

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question