having headache wtih codeigniter mod_rewrite ~! - .htaccess

I read lots of the mod_rewrite for codeigniter and lots of them were talking about creating a .htaccess file and inside the file with something like
I'm a beginner with codeigniter so I'm learning from youtube tutorials.
at first I only have apache 2.2 installed to run my php and after using codeigniter with mod_rewrite I realize it's easier to install wamp so I uninstalled apache, mysql then installed wamp which has everything.
After that I continued with the tutorial on youtube about mod_write. I activated the module in wamp.
Created this .htaccess file inside ci_intro which is the root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I went to the config/config.php and changed
$config['index_page'] = '';
things didn't work. I was getting the 404error then I was trying out few things in
RewriteBase /ci_intro/
and also even deleted the whole project and because I backed things up right before I try the mod_write. Even after I retrieved the backup. I still didn't get the error404 page.
I just keep on getting..
Since I'm using wamp, when I go to my localhost there's a section saying my project which is ci_intro...I click on it the image above comes out.
I put my mouse over to check what's the link showing when mouse over and the link shows
[CODE]http://localhost/ci_intro[CODE]
anyone know what's going on here?

That browser page you are getting, is a result of using a fake or unregistered domain-name... The browser is unable to resolve it to an IP address, so it "helps" you by reinterpreting your request as a search term.
This is happening because you are using "www.domain.tld" instead of "localhost" to access your website.
I'm not sure which WAMP distrubution you are using (there are many "WAMPs"), but your options are:
A) Edit the Windows Hosts file (C:\Windows\system32\drivers\etc\hosts) to locally resolve "www.domain.tld" to the local IP addres 127.0.0.1 (and make sure your VirtualHost or Server has that domain name as part of it's ServerName directive).
B) Use "localhost" instead... http://localhost/
C) Use a WAMP that automatically sets up website VirtualHosts for you and has a LocalDNS feature like Wamp-Developer Pro does - so none of the above matters.
Now once you get passed that, there might be some other issues... I'm guessing that .htaccess file should be in the DocumentRoot folder itself.

Related

Laravel project in subfolder of public_html gives trouble with .htaccess redirect

I've set up my VPS server and am trying to set up a Laravel project.
I have a /public_html/ folder with an index.html that's shown when visiting the website URL.
I have a laravel project in: /public_html/project_one/
The original index.php is located in /public_html/project_one/public/index.php
I want the website to show to Laravel project_one by default, but since yesterday I literally googled this for 4 hours, I tried every solution on stackoverflow, nothing worked... I think I've tried over 10 versions of .htaccess I could find.
The question:
Does anyone know how to setup the .htaccess inside /public_html/ so it redirects to my Laravel project?
I though I needed to upload my Laravel folder in: /public_html/project_one/ but is there a better location?
I want the main url to show the Laravel project. So www.mainurl.com is Laravel's project_one/public/index.php file. I do not want /project_one/ to be written in the URL!
Just out of curiosity, if I now visit: www.mainurl.com/project_one I get a 403 forbidden.
Failed solutions
In /public_html/ I tried to add .htaccess with:
DirectoryIndex index.php
#Redirect to /project_one/public if you haven't already and the IP is okay
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} !^/project_one/public
RewriteRule ^(/lucaphoto)?(.+) /project_one/public$2 [L]
#if IP does not match and you ARE in the folder, then Redirect to root
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} ^/project_one/public
RewriteRule .? / [R=301,L]
This gives me something really strange:
On Chrome: it redirects me to www.mainurl.com/project_one -> And then gives me a 403 forbidden error.**
On safari: it redirects me nowhere but gives me this error:
Forbidden. You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Laravel's original .htaccess File
By the way, Laravel has an original .htaccess file at /project_one/public/.htaccess. And it looks like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
The actual laravel application ( anything but the public folder ) is not supposed to be public and therefore should not be placed inside the public ( public_html ) folder.
I actually tried severel things to get something similar to your setup running. My conclusion was - that only changing the .htaccess file will net e enough to run laravel inside a public folder.
The most easy solution to quickly setup a laravel application is to use a subdomain which directly points to the public folder.
www.mainurl.com /* points to .../public_html/ */
laravel.mainurl.com /* points to .../laravel/public/ OR ( but not good ) */
/* points to .../public_html/my-project/public/ */
What you actually will need to do then is to change the root of your domain / subdomain to point into another folder - no changes to .htaccess are needed then.
Update
If your site is www.example.com and you want your laravel app to show when opening this site you have two options.
Put the content of laravels public folder to public html and change the references to fit the public_html instead of public folder.
If your Filestructure on the server is like .../var/stuff/.../public_html/ then upload everything to ../var/stuff/my-project and then go to your hosters interface and make an internal redirect to the ../var/stuff/my-project/public folder and everything will be fine without chaning anything in your laravel code. ( anything but .env )
So the actual problem is that your domain points to the folder public_html, instead of the public folder of your app. However please dont put your app into public_html directly, put it parallell to it and change where the domain points to.
if you give us some information about your hoster we might can provide a guide

resolving index.php issue at url laravel htaccess

I know this question is asked alot and there are alot of answers on "how to resolve index.php issue in laravel".
However, I tried multiple ways in order to solve it from .htaccess on live dedicated server with WebsitePanel in order to remove index.php from URL. I tried a couple of ways however let me describe the issue here, index.php not only have changed the url, but also some of the css and javascript stuff are not loaded as well while most of them are loaded, CSS seems pretty fine but fonts are also changed.
It was working well at a shared host but here in a dedicated host it has alot of problems.
Is there a .htaccess code to solve this issue? and does index.php affects on CSS and is it normal?
my current htaccess is as follow:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>
You don't need to modify index.php or .htaccess. If you did this, revert to original files.
To remove index.php or public from URLs, you need to setup virtual host for Laravel project (there are instructions both for nginx and apache).
After that restart web server.
This is the most common problem in Laravel. When you upload your code to a webserver, your page will be in
www.web-something.com/index.php
So there are 2 things you should do,
1.Change the .htaccess file and also
2.Change the Virtual Host Settings in your server. Link :for setting up a virtual host in apache
After this you will be able to visit the directory just fine. Also about the CSS , problem , Its probably because of the virtual host settings. Itll get fixed up once you point everything to the right directory.
For IIS Windows Server, the .htaccess needs to be translated to web.config and this works like a charm.
here is the link:
How to enable modrewrite on IIS Web Server
In case Someone needed this in future!

Remote site not working on local server

So I'm setting up a local environment for testing and development. We use CodeIgniter as our framework.
But when I copy the whole server to the local server (I have XAMPP), and navigate to the root, all I see is a directory structure - it doesn't display anything at all that I would expect to see from the website.
I spent 4+ hours (over several days) trying every .htaccess and httpd.conf suggestion I could find on Google, stackoverflow, these forums, and more. I am able to get a 500 server error when adding garbage to the .htaccess file, so I know it's being processed. But I think my problem is possibly unrelated to the .htaccess file settings. (I don't really care if index.php shows up on the URL bar locally.)
There is no index.php on our server's root (again, our site is built with CodeIgniter). Nor anywhere else in the site's directory structure, (except /application/views/user/template/original). When I access the site live, in the URL bar it pulls up the domain name followed by: "/user/login". Looking into the /application/views/user folder shows a login_view.php, but when I try to access it directly, I get an Access Forbidden 403 error.
Per this solution, I also tried changing the DocumentRoot (in C:\xampp\apache\conf\http.conf) from "C:/xampp/htdocs" to "C:/xampp/htdocs/othersites/mysite" Same result.
How is the site loading remotely, but not locally?
Check your base_url in config.php
Here is working .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It turns out, for some reason, the site's root index.php wasn't in the git repo that I cloned from. I have that now, along with another (different) .htaccess file.
After changing the base_url in application\config\config.php to my localhost variant, it's working!
If I ever figure out why they didn't have index.php in that repo, I'll let you all know...

Codeigniter 2 shared hosting sub-directory installation

I know this has been asked a lot of times before, but I did search a lot without finding an answer. So I'm hoping someone will help me out. I have a shared hosting and inside the public_html folder I wish to install my CI app. The sub-directory name is "hrms".
So I uploaded all the CI files to hrms. Now when I visit http://www.example.com/hrms/index.php/login/do_login I get the famous error No input file specified. I have tried with .htaccess file with several variations that I could find, but none have helped. The http://www.example.com/hrms/index.php is working, so I'm guessing all the config is all right.
What am I doing wrong? Also, is the .htaccess file a must, even if I intend to access the site via full URL?
==== .htaccess =====
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /hrms
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /hrms/index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /hrms/index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /hrms/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Much ado about nothing.
===== UPDATE =====
I've now discovered that the problem is with GoDaddy hosting (GoDaddy and CI have a hate-hate relationship, it seems). The trick is to define your index.php as index.php? (notice the question mark) in the config.php file.
Nevertheless, many thanks to everyone who put effort into it!
Please note: If you're fine with ugly URLs like http://www.example.com/index.php?/HomeController/myFunction and aren't using routing (like me for now), there is no need for the .htaccess file.

cakephp htaccess for production install

So, I have cakephp installed in what I believed to be the appropriate way for production code with actual cake files above the public_html folder. The app folder is removed from the cake folder and placed at the same level.
Loading the home page works fine with the databases and the debug working.
However, in trying to run some test files I get a 404. Obviously, I need some way to direct something like www.example.com/posts/index to the proper location. I am not sure as to why this is necessary since the index.php file tells cake where the app directory is located?
Also, if I need to use the .htaccess file, how do I point to the proper location and exactly what am I pointed at?
Update - I get the errors when I follow the blog tutorial and navigate to www.mywebsite.com/posts/index
If you have a production install the url example.com should point at app/webroot/, and the only .htaccess file you need is the default one from the webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Be sure to use the .htaccess file which corresponds to the exact version of CakePHP you are using as it has changed over the years.

Resources