Codeigniter and WAMP Routing Issue - What am I missing? - .htaccess

I'm scratching my head for almost two days now, thought some expert advice can help me here.
I got a CodeIgniter application I need to maintain (version 2.X), and this is my first experience with it. The structure of the application is:
myApp
application
cache
certs
config
controllers
...
modules
moduleA
controllers
models
views
moduleB
controllers
models
views
...
third_party
views
cgi-bin
...
system
themes
uploads
I installed WAMP, and throw the entire myApp under c:\wamp\www. Another steps I did:
1) Changed the 'listen' port of the Apache since I also run IIS on my machine.
2) Enabled the Apache rewrite module.
3) Set the 'all' and 'all granted' in the <Directory .../> section:
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
4) Set correctly the database name in the 'database.php' config.
5) Verified .htaccess file is located under myApp folder, and the content of the .htaccess is this:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
6) In 'routes.config' the default controller is: $route['default_controller'] = "login";
With these steps I was able to host this application locally and work for a while. But, I had to change my Windows user password, and after rebooting my computer I receive 404 errors all of a sudden.
I am able to browse to the 'login' page via http://localhost:port/myApp/index.php (or just http://localhost:port/myApp), but from there I receive only 404 error messages. I can browse with the full url though:
http://localhost:port/mpApp/index.php/login/forgotpassword - Accessible
http://localhost:port/myApp/login/forgotpassword - 404 error
Now, I am not sure whether it's related to my Windows user password change, but this issue became a voodoo, since I swear I could work and browse locally to all pages. I also reinstalled WAMP twice and repeated
the process above just to make sure I'm doing things right.
Can anyone think of something I am missing here?

Found the issue, at least the one worked for me:
In config.php (under ...myApp\application\config) I changed the value of $config['uri_protocol'] from 'AUTO' to 'PATH_INFO'.

Related

Doing URL Rewriting and Redirections (.htaccess) with same code working both on WAMP localhost and remote folder?

first of all, I'm sorry for this umpteenth topic about this kind of problem.
I've tried to adapt other topics to my problem for months without being able to figure out how to do. That's why I'm writing today, it's really bugging me and as of today, I can only successfully do URL rewriting on remote but always coding in production remote folder isn't reliable solution.
This is what my file tree look like :
Firstly, I'd like to be redirected from the root of this 'template1' project to the root of the 'public' subfolder ; and secondly, I'd like to rewrite URLs so this kind of URL :
template1/index.php?route=qwertyuiop
turns into that :
template1/qwertyuiop
Both these things I want work but only on my remote folder on Ionos and I had to do weird things. For example for the redirection, I'm directly linking domain to subfolder and for URL rewriting I do :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
Anyways, this works fine on remote folders and when I do PHP header("location:/azertyuiop") it works fine but in localhost it tries to search at the root of WAMPserver and I don't know how to proceed to fix it while keeping same code for both local and remote.
If any of you could help me figure out how to deal with this problem, it would be really appreciated as reading topics and putting whatever I can in my .htaccess doesn't work on localhost.
Ok, sooo thanks #MrWhite for basically telling me about VirtualHost. I never saw about it in any topics so I was searching maybe in the wrong direction.
Everything is working fine, now. So in case in the future someone gets through it, I will explain what I did to make it work in localhost. What I will tell is translated from a website I've found in my native language ( How to configure VirtualHost (French) ).
STEP 1 : edit Apache's config in Wamp
In the 'httpd-vhosts.conf' file located in 'C:/wamp64/bin/apache/apache2.4.46/conf/extra/httpd-vhosts.conf' (in my case), I had to add these virtual host lines :
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "${INSTALL_DIR}/www/projets/projets_persos/tests/template1/public"
ServerName template1.local
ServerAlias template1.local
ErrorLog "logs/template1.local-error.log"
CustomLog "logs/template1.local-access.log" common
</VirtualHost>
Then I had to modify Apache's main config file called 'httpd.conf' located in 'C:/wamp/bin/apache/apache2.4.46/conf/httpd.conf' (in my case) and uncomment the following line :
#Include conf/extra/httpd-vhosts.conf (in my case, it was already uncommented)
After that, the website says to restart Wamp's services before step 2, which I did after step 2 below and it stills work without any trouble. So anyway, I guess it will be same for you, do it now or after step 2.
STEP 2 : edit Windows' hosts file
At bottom of the 'hosts' file located in 'C:/Windows/System32/drivers/etc/hosts' I added the following line at bottom of the file to override the previous rule :
127.0.0.1 template1.local
Aaand, that's all.
=-=-=-=-=
As a proof it's working well, here's a screenshot of my project :
Here you can see on the picture I exploded my route in an array. I do this for personal purposes, to be able to route according to whatever bit of string I want. If you want to get rid of the 'public' value in the route, just type $_GET['route'] = str_replace('public/', '', $_GET['route']); before putting each of its fields in the array. Then, it will look like this :
Also, of course, I used .htaccess to be able to do URL Rewriting, here's my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
It's a bit off topic but in case you'd need to know, the RewriteCond lines allow to type in the true URL of assets that have these extensions and it won't rewrite as they are true URLs.
=-=-=-=-=
Anyway, this is the end of my solution, thanks again for helping me and all's well that ends well. The End.

Migrating CodeIgniter from WAMP to Ubuntu 12.04 LTS LAMP

After I successfully installed Ubuntu 12.04 LTS LAMP on my local machine, following this TUT. And installed phpmyadmin with this instruction. I migrated my working CodeIgniter project inside /var/www/ and updated my database. Everything seems to be working fine except i'm having a 404 error saying:
GET http://192.168.1.11/quantum/login/ 404 (Not Found)
The following error occured: error Not Found
GET http://192.168.1.11/quantum/user/ 404 (Not Found)
The following error occured: error Not Found
After hours of desperate troubleshooting I found some possible causes.
.htaccess (already updated)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
mod_rewrite (already enabled)
but still, i cant seem to make it work. any ideas? is there more to be configured to make the project running?
(dumb) Have you checked all folders have successfully been copied?
Have you changed your base_url in the config file? (/application/config/config.php)
When mod_rewrite is enabled (to remove the index.php in the URL), your index_page item in the config file must be blank.
If you have already checked these things, try disabling mod_rewrite in order to track if this is your issue.
Turns out I forgot to reconfigure my htaccess by allowing override on my httpd.conf inside apache2.
<Directory /var/www/quantum>
AllowOverride All
</Directory>
Works like peanut butter and jelly.

Laravel 4 Routing issue

i hope you can help me out as been scratching my head for ages..
I have the laravel 4 installed in a folder called 'myapp' www.example.com/myapp/
I'm calling this but i'm getting app undefined..
Route::get('login', function(){
//do something
});
The only way i can get it to work is this way, but it messes everything up all the styles etc..
Route::get('/myapp/login', function(){
//do something
});
And this is my current .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Does anyone know how to get it to work just for the myapp folder?
Thanks in advance.
I've now figured this out.
I needed to change the .htaccess file from this
RewriteRule ^ index.php [L]
to this
RewriteRule ^ /myapp/index.php [L]
I think your web server might be misconfigured. A correct web server configuration usually requires no changes to .htaccess.
Normally, using Laravel, you should have a DocumentRoot directive that points the web server to the public directory of your Laravel installation.
Exactly how you do that varies a little among operating systems. On my system, which is a development system running Ubuntu Linux, and which hosts multiple Laravel projects, I use multiple virtual servers. Ubuntu's configurations for these virtual servers are stored in /etc/apache2/sites-enabled. The configuration file for my calendar project (locally, calendar.dev) looks like this.
$ cat /etc/apache2/sites-enabled/calendar.dev
<VirtualHost *:80>
ServerName calendar.dev
ServerAlias calendar.dev *.calendar.dev
DocumentRoot "/var/www/calendar/public"
HostNameLookups double
</VirtualHost>%
If you're using "myapp" in place of the default "public" folder, then your DocumentRoot directive should point to "myapp" instead of "public".
If you're using "myapp" in place of the default "app" directory, you need to back up and rethink this. The "app" directory shouldn't be accessible to web users.
I agree completely with Mike Sherrill. Laravel ships with .htaccess config file that works "out of the box". There was some problems with older Laravel versions, but with L4 no. If you plan to add new virtual host don't forget to register one in /etc/hosts file. So check your server configuration.

Silverstripe mod_rewrite issue (I think)

A site I've been working on, which has been working fine on my local dev and live dev environments is giving me issues when I try to deploy it to a live server (the client wants to host it with their existing hosting provider).
I uploaded the site to the server and updated the database config as I have done many times before on both my and other's servers without issue. This time, however, I was presented with:
SilverStripe Framework requires a $databaseConfig defined.
When I removed the .htaccess file from the root folder, the site appeared, however, all the URLs appeared like so:
www.domain.com/index.php/page_name
After a few searches, I came across a solution to the index.php issue; to add the following to my _config file
Director::setBaseURL('/');
I did this and the URL's appeared correctly, however navigating to them would give me a 404.
I reinstated the htaccess file and narrowed it down to this block:
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1 [QSA]
When this is in place, I get the database config error mentioned above, when it's not there, my urls produce 404s
Does anyone have any insight as to what can be going on here? I've had a lot of back and forth with the host and he's not very knowledgable and can't offer any advice and I'm no genius when it comes to this side of things.
I'll assume you are using SilverStripe 3.1+ so the Director config could/should be placed in your YAML config file (the static will be deprecated):
Director:
alternate_base_url: '/'
Although this helps mainly on issues with base_tag.
The main ModRewrite issue might however be solved by adding a RewriteBase:
RewriteEngine On
RewriteBase '/'
You can use '/' or the folder SS is installed in if not the public root. This is usually automatically handled by the SilverStripe installer by checking $base = dirname($_SERVER['SCRIPT_NAME']); and other little things. Check install.php5 line 1483, you might be able to use this to figure out your RewriteBase.
If that doesn't work, try a fresh install instead of copying to the server your local install.
Do you use a _ss_enviroment.php to define your database config details? I had a similar experience like from in a project i migrated from SS 2.4 to 3.1.2.
Set this in your site _config.php
// Use _ss_environment.php file for configuration
//Please note that your system should have a file, _ss_environment.php, with database connectivity data,
require_once("conf/ConfigureFromEnv.php");
global $database;
$database = '';
I hope this helps

index.cfm append with SES URL in MURA

Recently working with MURA CMS with RAILO on UBUNTU. I am installing MURA in inner folder of root directory.
public_html >> website.
Following code added in .htaccess to rewrite URL to run website without index.cfm and website directory.
Options +FollowSymLinks
RewriteEngine On
DirectoryIndex index.cfm
RewriteRule ^$ /website/ [R]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^website/([a-zA-Z0-9/-\s]+)$ /website/index.cfm/$1 [PT]
So my url http://example.com/website/privacy/ rewrite as
http://example.com/website/index.cfm/privacy/
I think rewrite rule should work correctly as I have tried some online validator and giving me correct result but if run it into MURA it produce URL like
http://example.com/website/index.cfm/privacy/index.cfm
I am not sure who is adding last index.cfm (apache or mura) and this take me to 404 page everytime.
Please help... this driving me crazy..
Thanks,
Pritesh
UPDATE
I have same site setup with windows/IIS 7 under subfolder of root and work fine though, if that help
To take off index.cfm of the URL, you have to edit file settings.ini.cfm
To edit this file
go to Modules / File manager
Then tab Application Root
Select folder config
Then right click on settings.ini.cfm and edit
In this file, siteidinurls and indexfileinurls have to be at 0
siteidinurls=0
indexfileinurls=0
After change, you have to reload application by clicking on Reload application on the Settings menu at the top of the window.
Thanks Matt and Mael for spending time for this issue.
Finally figure it out that TOMCAT was causing issue and adding index.cfm at the end.
<url-pattern>/website/index.cfm/*</url-pattern>
Add above URL pattern in web.xml file and it start working fine.

Resources