Url routing errors in php in codeigniter - apache

My login form on front page is displayed, but when it posts to other pages, the post does not happen. THe problem is that the url is like: http://sitename/users/action which is a 404 not found url. But when i hard code the path to controller, (that is, stop using base_url + "/users/action" and use base_url + "/system/application/controllers/users/action") it starts working. How can i fix this problem?

Are you using .htaccess to hide index.php? If so, you need to take that into account with your routing. If not, you need to include it. e.g. if you're not hiding it, try:
base_url+"/index.php/users/action"

You can also try your config/config.php folder and fix your $config['base_url']...hope that helps.

i had the .htaccess file in the wrong folder, inside the system/application/config/ folder, instead of the root folder. after i pasted the file in the root folder, the problem was solved.

Related

How to remove extra folder using .htaccess?

I have been playing with booked scheduler for a client but noticed that when I hit a certain part of the site it doubles up a folder in the URL and causes a 404. I believe it should be possible to fix using .htaccess but I'm unsure where to start.
The URL should be
domain.com/Web/thing.php
but the button is loading
domain.com/Web/Web/thing.php
Is it possible to fix the broken link using .htaccess so it loads the page without the second folder?
Try:
Redirect /Web/Web/ /Web/
This will need to go in the htaccess file in your document root.

How to enable urlManager in Yii for virtual directories?

I'm using xampp and tried to put my yii folder and the webapp folder separate from the htdocs directory. I've followed the instructions from here:
http://el.web.id/how-to-add-virtual-directory-alias-on-apache-xampp-165
I was able to run the main page all right, but the other pages just return a not found status. May I know how to fix this? I'm not even sure if the main problem comes from Apache or from Yii. Thanks a lot.
Oh, I get it now. We'd just need to add a rewritebase on the .htaccess file that matches the alias.
RewriteBase /aliasfolder
This is for reference purposes.

URL Rewrite for relative URLs on localhost

I just moved my website to a folder (called test) inside the root of my Apache web server and now I am getting 404 errors while the page tries to fetch different resources.
When I looked at the urls - they seem to be pointing to the root of server as they are root relative URLs (as opposed to be pointing to the folder [test] inside the root).
For example: when the index page of my site has a reference to an image like
<img src="/images/img-1.jpg" alt="Image 1" />
The page when executed, tries to fetch the image from the following url
http://localhost/slider-images/img-1.jpg
instead of accessing the image from the url
http://localhost/slider-images/test/img-1.jpg
I have been trying various options like having a ReWriteBase etc, but that doesn't seem to be working!
What works instead is me changing the resource path to be an absolute one, but that is just too much of work for me to do for all the resources!
<img src="./images/img-1.jpg" alt="Image 1" />
Any help is much appreciated.
Thanks
Update
A similiar question has been posted earlier, but I don't a response that solved the issue
Converting relative URL requests to absolute URL request using mod_rewrite
After hours of troubleshooting, I did a workaround which can be used a temp fix.
Posting it here to help those who possibly could be having the same problem.
Simply changed the DocumentRoot in httpd.conf file to point to the sub-directory where I had moved my website files for testing.
Hope this helps those who can make use it this fix.
I would still be really interested to know of a way to address the root-relative URL rewrites via htaccess and hopefully someone here would be able to help.
Thanks!

XAMPP Error with using ErrorDocument in .htaccess

I am using a .htaccess file for a short url system that I made. It is supposed to use a file, sudir.php, to find the url that the "code" that was entered is for. But whenever I goto the page at http://localhost/shorturl/t10m3S which doesn't exist so it is supposed to redirect with sudir.php, but it only takes me to a generic "Not Found" page.
This is what i have in my .htaccess:
ErrorDocument 404 /shorturl/sudir.php
If I change it to my phptesting folder, it shows the index of that folder. If I change it to just the shorturl folder, it still gives me the generic 404 error page. If I remove it completely it shows the default page from Apache. So it basically seems like Apache or .htaccess or something doesn't know that the shorturl folder exists even though I can access it and it works. It seems all I need is for it to acknowledge that the folder is there and actually load the sudir.php file, but I don't know what to do.
Additional Info:
I am using a .htaccess file in a different directory to redirect to YouTube pages like how youtu.be does and it works perfectly fine. I did have the same problem with it though at first, but I just renamed the folder it was in and changed the .htaccess to correspond and it started working. I have tried the same with shorturl, but it did not work.

How does Code Igniter know that index.php is not a directory?

My Code Igniter app has urls like this:
http://servername/contexttroot/index.php/Sessions/login/
My question is, when the url is parsed how does Apache know that there isn't a folder called index.php? If I were the parser, that's what I would be looking for :)
I know it works and CI's index.php gets called but I don't understand how this works. Maybe dots aren't allowed as part of directory names?
UPDATE See the comments on the accepted question for details, there are lots of details to what I am asking.
CodeIgniter basically performs rewrites of the URL by searching for the index file name "index.php" in your URL. Look in CI's config file for this line:
$config['index_page'] = "index.php";
Try changing that to something else and see if it still works.
Edit: OK, to answer the question Juan posed, the way Apache knows that index.php isn't a directory is because a file and directory can't have the same name in the same directory. If index.php were simply a directory, Apache would go into it and search further. If it is a file, it will run the file.