Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]clean urls and htaccess problem - host is useless
#1

[eluser]Cgull[/eluser]
Hello good people,

I am having a problem with clean urls and htaccess which I am trying to solve with my host for 2 days now.

It is getting ridiculous how I have to explain myself for about 4 times already with no solution from the hosts side.

I hope someone here can myabe help.

I am using codeigniter 2.1.2, WAMP PHP 5.3.13, Apache 2.2.22

I have uploaded my site to the live server under: public_html/dev

I have a controller controllers/admin/admin.php that checks if the user is logged in.
If the user is logged in it calls:
views/admin/dashboard/index.php

If the user is not logged in it calls:
views/auth/login.php

My htaccess file:
RewriteEngine On
#RewriteCond $1 !^(index\.php|assets|images|robots\.txt|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

If I go to the live site thinklocal.co.za/dev/admin I get this: No input file specified.
On my local machine it works fine.

Can someone please help?

At last I found an htacess that works:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Halleluiah
#2

[eluser]CroNiX[/eluser]
It would be best to remove this line:
Code:
RewriteCond $1 !^(index\.php|images|robots\.txt)

because you are using these lines
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
which are better and already cover the above rule (they say if the request is not an actual file or actual directory process via index.php). You also won't have to update it if you add a new directory or something (like images).

Code:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /dev
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Also, usually RewriteBase requires a trailing /, like /dev/
#3

[eluser]Aken[/eluser]
CroNIX, the benefit of adding the first conditional in addition to the file/directory ones is that you can exclude entire directories from ever routing to CodeIgniter (and prevent unnecessary overhead) in the first place. If there's a request for a non-existent file in my assets directory, for example, the file/dir conditionals will not fire because it doesn't exist. If I know that my assets directory will only have static assets, I never need it to go to CI.
#4

[eluser]CroNiX[/eluser]
You don't need both though. You don't need the -d/-f lines at all if you use the first exclusionary rule. But you don't need them both.
#5

[eluser]Cgull[/eluser]
Thanks guys.

Now I just need to decide if I want to use one condition or the other Smile
#6

[eluser]Aken[/eluser]
[quote author="CroNiX" date="1364512288"]You don't need both though. You don't need the -d/-f lines at all if you use the first exclusionary rule. But you don't need them both.[/quote]

There are times where one condition may apply and the other won't. For example, you have a one-off file that you upload to the root directory for whatever temporary/permanent use. If you have only the $1 exclusionary rule, and that file/path isn't defined in the rule, the request will be routed to your application even if the file exists (and may provide a ton of headaches trying to figure out why your obviously-existing file is showing a CI 404 error).

There have even been instances where, since some applications autoload various resources (and some even using hooks to perform actions), code is run unnecessarily because a not-found asset caused a 404 error to run through CI. Sure, that's poor application logic, but TONS of people do it because topics like that can be somewhat advanced.

No, the $1 exclusion is not required (the -f/-d flags should always be used). But they don't conflict with anything or slow things down. It's a good, recommended solution for people who don't understand things like static, non-cookie domains, CDNs, etc.
#7

[eluser]CroNiX[/eluser]
Just recommending what's in the new user guide and what's always worked for me. More often than not people aren't trying to exclude things (or they wouldn't have their application/system dirs in their public dirs in the first place) and those other rules only complicate and/or break things for them. If course, if they understand apache/htaccess they already know how to do what you are saying and wouldn't be asking the simple questions here.

https://github.com/EllisLab/CodeIgniter/...l/urls.rst
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#8

[eluser]Aken[/eluser]
You may be explaining a simple solution that works for you, but you're recommending that he remove something that both A) does not impact the original problem, and B) serves a useful purpose. I'm trying to explain that purpose, rather than just saying "don't use that because I don't".
#9

[eluser]CroNiX[/eluser]
It works for 99.9% of what people here need. Feel free to issue a pull request and amend the docs if you feel they are inadequate.
#10

[eluser]Aken[/eluser]
It probably does work for most people. But again, I'm just explaining its benefits and why it's useful.

I'm also one of the most active contributors to CI as of late, so I know how to submit changes. But thanks. ;-)




Theme © iAndrew 2016 - Forum software by © MyBB