0

So I migrated my app from one host to another. Most of the app works through 'pretty urls' where /login.php becomes /login (which I access in my php through $_SERVER['REQUEST_URI'] ), however after switching hosts my htaccess code for this doesn't work anymore (chrome gives me a redirect loop error).

This is the code:

 Options +FollowSymLinks  
 RewriteEngine On  

 RewriteCond     %{SERVER_PORT} ^80$
 RewriteRule     ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]

 RewriteCond %{SCRIPT_FILENAME} !-d  
 RewriteCond %{SCRIPT_FILENAME} !-f  

 RewriteRule ^.*$ ./index.php  

Any idea what could be wrong?

3
  • Can you explain what RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R] does? it looks completely useless to me... Commented Jun 12, 2014 at 14:36
  • @Peter RewriteCond %{SERVER_PORT} ^80$ = Look for any connection over port 80. RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R] = Rewrite everything ^(.*)$ to http://%{SERVER_NAME}%{REQUEST_URI} and make it the [L] last rule, which is a [R] redirect. If you want to make it permanent, change [L,R] to [L,R=303] `303 is the HTTP-code for 'moved permanently' Commented Jun 12, 2014 at 14:42
  • @OCIA i understand the syntax, if there is connection on port 80, redirect it to port http://, default port (80) = useless, infinite loop Commented Jun 12, 2014 at 15:05

1 Answer 1

2

If you want to redirect HTTP to HTTPS:

RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond     %{SCRIPT_FILENAME} !-d  
RewriteCond     %{SCRIPT_FILENAME} !-f
RewriteRule     ^(.*)$ index.php/$1

If you want to redirect HTTPS to HTTP:

RewriteCond     %{SERVER_PORT} ^443$
RewriteRule     ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond     %{SCRIPT_FILENAME} !-d  
RewriteCond     %{SCRIPT_FILENAME} !-f
RewriteRule     ^(.*)$ index.php/$1
Sign up to request clarification or add additional context in comments.

1 Comment

Edited a few times to match the source of the question a bit more (included a change to the RewriteRule ^(.*)$ index.php/$1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.