Redirect loop in codeigniter - apache

I have a site on my https://mydomainname.com.
While working today i had to change permission of a file to make or writable (although i dont think any problem was caused due to this ) and since then the site has gone into a redirect Loop. Site is built Up in php using codeigniter Framework.
My directory structure is :
/var/www/html/myprojectRoot
My server's default DocumentRoot is /var/www/html/
inside html i have .htaccess file as follows :
RewriteEngine On
RewriteRule ^$ /myprojectRoot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|javascript|images|robots\.txt)
RewriteRule ^(.*)$ /myprojectRoot/index.php/$1 [L]
My baseurl is set to https://mydomainname.com
I can see in firebug console that the sute is being redirected between
https://mydomainname.com and https://mydomainname.com/myprojectRoot
Can someone explain the issue.

Keep your /myprojectRoot/.htaccess like this:
RewriteEngine on
RewriteBase /myprojectRoot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
then inside /myprojectRoot/application/config/config.php you need to have these config settings:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Your root .htaccess should be like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!myprojectRoot/).*)$ /myprojectRoot/$1 [L,NC]

i think it is not the issue you might change the code.
You should check the code where you are performing your redirect function.
And there it redirects there might be a check to go in else it will take back from where its redirected.
And it become a redirect loop. From one method to another.

Related

Conditional URL rewrite

I need the URL example.com/app to show the content from example.com/app/dist
The following code does exactly this.
RewriteEngine On
RewriteRule ^$ /app/dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/dist/
RewriteRule ^(.*)$ /app/dist/$1
BUT I also need the URL example.com/staging to show the content from example.com/staging/dist
With the current setup, the url example.com/staging is showing the content from example.com/app/dist
The .htaccess while is located in the /app and /staging folder (but it has to be the same file)
In the htaccess file in your staging folder, change all instances of app to staging
Edit:
You can try using relative paths instead of hardcoding the app or staging, but Ive had issues in the past, especially if there are other rules in play.
RewriteEngine On
RewriteRule ^dist - [NC,L]
RewriteRule ^$ dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ dist/$1 [L]
The idea is to remove the leading / from rewrites so a relative path is used. So technically it wont matter whatever folder the htaccess file is in

AngularJS2 + Apache routing

I'm currently using Angular2 with Apache and I have a problem: when I use routing and navigate through pages, template syntax doesn't work, I just get an empty space in the place where {{}} is in the template. Also ngOnInit seems to be not working. When I use lite-server everything works fine.
EDIT1: I'm trying to run an example from developer's guide on routing: https://angular.io/docs/ts/latest/guide/router.html
https://angular.io/resources/live-examples/router/ts/plnkr.html
EDIT2: I'm also using CodeIgniter 3 and it already uses the following .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
It could be an issue with redirects/not-found files.
Try adding .htaccess file:
# BEGIN ServeStatic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# END ServeStatic

Rewriting ends up with not loading js / css

With the following .htaccess file, I obviously, get alot of 404's on loading scripts and css because the browser keeps looking in the wrong directory.
I am a newb at htaccess and have no clue about how to fix it.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ client/app/index\.html [L]
</IfModule>
Dir structure is as follows:
project /client / app / index.html
.htaccess is located in project directory.
I recomend you that redirect users with a 301 to correct path. This will end with your problems.
RewriteRule ^$ client/app/index\.html [L, 301]
If you are worried about seo look at https://support.google.com/webmasters/answer/93633?hl=en
All of the calls at your server are being redirected to your RewriteRule. Add a RewriteCond (RewriteCondition) to ignore CSS and JS files, if they exist:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^$ client/app/index\.html [L]
Explanation:
RewriteCond %{REQUEST_FILENAME} !-f
If the requested filename exists (css/main.css), do not go through with the RewriteRules.
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
If the file does not exist, but matches one of the extensions, do nothing. This is helpful because you get a 404 if css/main-2.css does not exist, rather than redirecting you to index.php.
And then finally is your own rule, which redirects all non-conditioned rules.
In your .htaccess file, this is what worked for me.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !=/index.html
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^ /index.html [R=301]
Thank you!

.htaccess RewriteRule not working, bad flag delimiters

My site previously uses URL's like this: /folder/page
Previously, you could prepend 'panel' in the URL to edit the current page: /panel/folder/page
We upgraded our CMS, and the new URL to edit the page is in this format: /panel/#/pages/show/folder/page
I am trying to add a rewrite rule so that we can still use the old way, but can't get it to work:
RewriteCond %{REQUEST_URI} !^/panel/#/
RewriteRule /panel(.*) /panel/#/pages/show/$1
Is there a way to do this? A 301 redirect should work too, I think.
Edit: here is my existing .htaccess:
RewriteEngine on
RewriteBase /
# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
Since "panel" is already used, I ended up using this redirect rule:
RedirectMatch 301 /admin(.*) /panel/#/pages/show/$1

.htaccess rewrite rule redirecting instead of rewriting url?

This is the content of my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)(/.+)? /negocio$2?shopURL=$1 [L,QSA]
RewriteOptions Inherit
It takes not found directories and transform them into a php variable while retaining the rest of the url. When I go to:
http://lujanventas.com/test/asdf
The address bar shows:
http://lujanventas.com/negocio/?shopURL=asdf
(It should still show: "http://lujanventas.com/test/asdf")
What am doing wrong?
Fixed it by adding a / after the 2.
RewriteRule ^([^/]+)(/.+)? /negocio$2/?shopURL=$1 [L,QSA]