Codeigniter, routing is not functioning on production server - php

I have 3 servers, a localhost apache server, a testing remote server and the production live server.
I have the same installation of codeigniter and site set-up on all 3 of them and on the localhost and testing servers routing without 'index.php' works 100%. On the Production server however, no matter what the URL says only the homepage (via the default controller) will be shown, it seems all routing rules are being ignored except the default one.
If however index.php is added in the URL then it will work like it supposed to.
For instance if the URL on the production site is: 'www.mysite.com/information' then the content that loads is form the default controller.
But when the URL on the production site is: 'www.mysite.com/index.php/information' then the content that loads is from the 'information' controller.
This is the contents of my htacess file: http://pastebin.com/cDaZVJ8A
This is my routes config file: http://pastebin.com/7Ewc2bwN
My $config['index_page'] is set to nothing.
I really dont know why its not working, the same setup on all servers in term of codeigniter itself, and mod_rewrite IS working on the production server.
I don't know what to do, how can I find-out what's wrong?

This is quite a common problem that often occurs when people move a codeigniter install from one environment to another. I have no idea why it occurs, could be a difference in server OS or apache settings, but the solution is often to add a question mark ? to the RewriteRule for the index.php in your .htaccess file.
Old:
RewriteRule ^(.*)$ index.php/$1 [L]
New:
RewriteRule ^(.*)$ index.php?/$1 [L]

Check your Apache virtual host configuration and verify that you have AllowOverride All in your directory definition.

Maybe something is wrong with your .htaccess file?
Once I had problem when I moved application to production server, because RewriteBase was set to some directory on development server.
On my production server application was in web root directory, so RewriteBase should be /, and i had /something there.
Once i had silly problem with upper/lowercases, when i moved site from development server (windows) to production (linux).

I had the same problem. I was using function to convert article names to URL's (slugify).
On localhost and on server this function returned slightly different urls.

Related

.htaccess directive behaves differently between Dev and Live environment

I have this .htaccess rewrite rule in my Live environment: RewriteRule ^./-v. /Dev1/index.php [L]
and this one in my local (Laragon) dev environment: RewriteRule ^./-v. /index.php [L] i.e. they rewrite to my index.php where I interrogate the URL. They are identical other than my root directory in dev is /Dev1/ (and just / in live).
In index.php I use $_SERVER['REQUEST_URI'] to examine the 'freindly' incoming URL (which may have come from a search engine) e.g. www.mysite.com/thingA/subthingB/-v.
In the live environment it works correctly, i.e. $_SERVER['REQUEST_URI'] gives /thingA/subthingB/-v but the development environment just gives /Dev1/. The local dev environment uses Laragon on my PC.
Obviously I want to keep my dev and live code as identical as possible - any idea why the difference?
Thanks for any help.
My solution ...
I didn't really get to the bottom of the problem - it seemed to be intermittent depending on the test data, and there seemed to be other strange things going on.
I have solved it by making 'localhost/dev1' my root directory in Laragon rather than 'localhost' - I hadn't realised how easy this was to do in Laragon. This will also help me tidy up a few other things.

after changing the wordpress adress and site address in localhost xampp then it not working anymore

I am new in creating a website using wordpress. I am using xampp to create a local wordpress website and my website run under: localhost/mysite. I want to import my local website to my live website https://vsaftest.wordpress.com/ by going to the setting of my local website and then changed the wordpress Address and site address from http://localhost/mysite to https://vsaftest.wordpress.com/. After that then I can not access to my local site using http://localhost/mysite anymore, and inside the website https://vsaftest.wordpress.com/ there is nothing there also. I know that I made a mistake here but then anyone can help me how can I change back so that I can access my site from localhost :(
I've never used Wordpress before, but going purely from your desription, you seem to think that changing a setting on and for your local machine will somehow affect the settings on a remote machine.
and inside the website https://vsaftest.wordpress.com/ there is nothing there also
But was there nothing there beforehand either? In other words; Nothing's changed?
I think the reason you cannot view your local site anymore is precisely because you made the change you said you did. Instead of its changing the remote machine (which it probably doesn't do...I don't do WP dev, so I don't know for sure) it changed your local machine.
Can you not just change wordpress Address and site address on your local site back to what it was before?
There are many pitfalls one might encounter when moving a Wordpress website from a local development environment to production. Here are the main things to remember and look out for.
Htaccess
When developing in Xampp it's very common to include the website's directory name in the .htaccess' RewriteBase and RewriteRule. Assuming your production website will be situated in the root directory you'll want to remove the directory references from your .htaccess file.
For example your development .htaccess file might look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite.com/index.php [L]
</IfModule>
# END WordPress
But in production you'll need to adjust it to look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
One good development practice you can adopt is creating .live and .dev htaccess files. Create .htaccess.dev and .htaccess.live files and store your development and production htaccess data in them respectively. Your real .htaccess file will then contain the current active data and you can easily copy/paste from the .dev and .live files to it if needed.
Database
When you move a Wordpress website to production you must also create a production database for it. Make sure the database created has the same collation as the development one and that the database credentials in your wp-config.php file are updated to reflect the production database user, password, etc. Remember that if your WP_DEBUG variable is not set to true database errors will not be shown if a database connection error occurred in your production website. Because of that database errors in production more often than not lead to a "white screen of death".
Another thing one must make sure (and you already mentioned in your question) is that the siteurl and homeurl keys in your wp_options table are updated to reflect the production website url. In case multiple domains exist (for example .com and .co) one can enforce the correct url by defining the WP_SITEURL and WP_HOMEURL constants dynamically within the wp-config.php file.
PHP version
Last but not least, make sure the PHP version required for your website is compatible with the production server's PHP version. 2017 is a transitional year in terms of PHP support. Whereas Xampp already supports PHP 7 sadly many servers still do not.

Using Codeigniter application on freeBSD system

I have freeBSD installed on IBM server. There is also apache, php and mysql installed on the server. A PHP application running on this machine is working just fine, but our new version of the same application developed in Codeigniter gives a "Page Not Found" error.
The thing is the application is accessible and runs well (only the non-english character are displayed not well) if the index.php is included in the url.
I have modified the file .htaccess to remove the index.php from the url, I kind of need to use the .htaccess in the application's root directory. This (using .htaccess) is actually causing the error.
Please let me know what configuration do I need to do.
Edit:
Bellow is the content of .htaccess in the root directory of the application:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /football/index.php/$1 [L]

Deployed Yii app don't build url properly to domain subfolder

EDIT (a solution):
In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where mi virtual server is hosted into) redirects the requests, to append the string containing the virtual folder's name.
I'm not sure if this was the best solution, but it's a solution. So if you face a similar problem, you might want to contact your server administrator.
Here's the detail of the original problem and some of the options I tried, just for reference:
I've been developing a Yii application for a couple of weeks, and it works perfectly on my local server, but I'm having some troubles to make the URLs work properly when deploying the app.
In the server, I have an structure similar to this:
/www/MyApp/(index.php, protected folder, etc)
/www/yii (the framework is located here)
And I can access my website using an URL like this:
www.somedomain.ac/VirtualFolder/MyApp
My problem is that all the links generated by yii are pointed to (for example):
www.somedomain.ac/MyApp/index.php?r=controller/index
instead of
www.somedomain.ac/VirtualFolder/MyApp/index.php?r=controller/index
I tried modifying the urlManager section at the configuration, and for some reason adding these rules:
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
make some of the builded URLs point to the proper action, with the complete URL, but still, other ones won't work (all the ones that send a form to the server).
I've been trying other solutions to similar problems during a couple of days (like changing the app's basepath, adding "VirtualFolder" to it) but they don't seem to work.
Suggestions on how to solve the problem will be very appreciated.
Thanks.
============================================
EDIT: I am trying to do it with an .htaccess file like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} somedomain.ac$ [NC]
RewriteCond %{HTTP_HOST} !VirtualFolder
RewriteRule ^(.*)$ http://somedomain.ac/VirtualFolder/$1 [R=301,L]
And I copied it to my web root, but not working yet. Also tried copying it to MyApp/protected folder and directly into MyApp. Am I missing something?
Thanks.
You should try to add RewriteBase directive to .htaccess file
(how the problem was solved): In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where my virtual server is hosted into) redirects the requests, to include the string containing the virtual folder's name.
So if you face a similar problem, you might want to contact your server administrator.

Apache site root for development directories on localhost

I think I'm missing something and don't think I really understand how rewriteBase works.
The problem I have is that I have a production site where the site is in the root directory yet I have my development site in a localhost subdirectory. Eg http://www.sitename.com/ vs http://localhost/sitename/
If I have for example an images folder I want to reference the images from the site root by using the initial slash in the href. Eg Using a relative href (without the initial slash) is not an option. This will work on the production site but the development site is looking for http://localhost/images/imagename.jpg instead of http://localhost/sitename/images/imagename.jpg
So I thought all I needed to do was setup the following in my .htaccess file to force the site root to my subdomain within the development environment:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /sitename
But this still uses localhost as the site root instead of localhost/sitename.
Can anyone please give me some pointers?
-------------------------EDIT---------------------------
I stopped trying to do this in the .htaccess file and tried to just use the html command but this also didn't work.
In the end I set up Virtual Hosts in Apache on the local server but it seems like such an awful lot of overkill to just change the site root. I'm also concerned that other developers on the LAN network won't be able to access the site properly via the virtual host.
I'm really needing some 'best practice' advice please on setting up a workable development environment in WAMP.
RewriteBase alone, basically, tells Apache where to apply the RewriteRules. Here you don't have any. By the way, you can either remove the RewriteBase directive altogether, or change it to:
RewriteBase /
The following two lines should get it to work for your development environment only:
RewriteCond %{ REQUEST_FILENAME } !-f
RewriteRule ^(.+)$ /sitename/$1 [L,QSA]
These two directives mean: "if the requested file does not exist (-f), and only in that case, rewrite the url prepending /sitename/ to the requested URI ($1)".
For more info you can have a look at Apache mod_rewrite docs and Apache URL rewriting guide.

Categories