.htaccess not working - php

I have a .htaccess file to remove the index.php part of the codeigniter-style URL. It's been working fine on one computer but when I copied the file over to my laptop it doesn't seem to do anything. I'm using localhost on both machines. They both run mac osx 10.6 with the bundled apache and php and the latest version of mysql. Everything works fine, it's just the .htaccess that doesn't do what it should. Is there any setting that I might have changed on my first machine and forgotten about?!
EDIT:
I'm wondering if there is something wrong with my CI setup now. If I load the base_url ie http://localhost/~User/project/
then it loads perfectly, adding the index.php.
My config file has
$config['index_page'] = '';
However, as a test I returned this value to 'index.php'. When I loaded the base_url after this it returned: http://localhost/~User/project/index.php/index.php/controller/method
Does this suggest anything to anybody?

SOLVED:
I added a new directory command to my httpd.conf file which targeted the specific site I was working on. Seems to be happy now, but not a very satisfactory way of dealing with the problem if I have several codeigniter sites in my web root.

With just a shot in the dark do you have mod_rewrite installed on both?

If your on Ubuntu, you need to edit /etc/apache2/sites-available/default.
sudo vim /etc/apache2/sites-available/default
Where you see lines that say AllowOverride change it to say:
AllowOverride All
You may also need to enable mod rewrite:
sudo a2enmod rewrite
Then, restart the Apache server
sudo /etc/init.d/apache2 restart

Are you sure you have changed the name of the root folder?
Here is what I do:
I put this on my root folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rootFolder/index.php/$1 [L]
and in the path you replace "rootFoldel" with the name you are using.
hope that helps!

maybe you changed the path relative to the server root. it can breaks .htaccess and may be solved with a RewriteBase /path/to/folder/ statement
edit
since the problem not seems to be this one above, you could also check the error.log file in the apache folder (probably in the logs folder). it may have your answers and it can tell you if the .htaccess is getting parsed wrong or not parsed at all.

Related

Symbolic links not working on apache 2.2

I am experiencing a strange issue regarding displaying symbolic links. I have copied existing working code from my development environment, to a test environment. Looking at the code it should work. This makes me think that the issue might be elsewhere but I do not know where to look.
I am using Apache 2.2 on a CentOs 5.8 machine
All files and folders under document root including root folder is owned by apache
This are the lines of code in the vhost file
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /$1.php [QSA]
When I go to http://example.com/home
I get this error in the error log:
File does not exist: /var/www/my_document_root_folder/home
If I add .php to the URL it works:
http://example.com/home.php
The exact same RewriteRule works fine in my development environment. Could the issue be somewhere else and not in the actual RewriteRule?
I copied my development vhost file to this test environment. I only changed the ServerName, DocumentRoot, ErrorLog paths etc.
Any help is much appreciated, it's driving me bonkers.
-M
I have answered my own question. It turns out that I made a spelling error on one of the the paths. Once I fixed that everything works fine. Feeling a bit stupid right now :(
-M

How to replicate MAMP configuration to Ubuntu server

I'm having an annoying problem, i've developed a MVC php application, which of course uses a lot of redirects by controllers to controllers and so on.
Well, here's the issue.
On my MACs (note that i'm using a plural) works fine. Different versions of OSX, same version of MAMP on each one, same configuration of MAMP on each one. Even on the macBook Pro of the my office colleague it works fine with MAMP.
But when i move my application on a ubuntu server it causes a REDIRECT LOOP
between the login controller and the home.
After various experiments i think that the problem is the different configuration from MAMP to UBUNTU.
On MAMP i'm using the php 5.6.10 Version, enabled mod Rewrite (i use .htaccess to rewrite the url). Well, i would like to try to move my MAMP config to the ubuntu server. But i don't know how.
In MAMP i have 2 possible directories where the php.ini is located.
1) bin/php/php5.6.10/conf/php.ini
2) conf/php5.6.10/php.ini
Both of them are edited at the same way. I also think that the problem is inside the Apache2 config and not inside the PHP config, but i'm not 100% sure.
Keep in mind that i'm not very familiar with the htaccess files, so the rules inside my htaccess comes from a codecourse tutorial. But however on MAC it works...
However, here's the .haccess file that handles the URL rewrite:
Options -MultiViews
RewriteEngine On
RewriteBase /astrid/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
AddType 'text/css; charset=UTF-8' css
Also if you want to take a look to the project code here's the git repository:
Astrid
I'm stuck and i don't know how to figure this out! D: Any kind of help is extremely appreciated! Thank ya'll!

Cannot run project by CodeIgniter

I have problem with my project. Because this is a secret, I can not publish my site here. I am sorry for this and this is my case.
I have a project based on the CodeIgniter framework, I run it successfully on localhost but when I use SVN to commit this project to my hosting. It do not run. I am trying to delete all file and commit only index.html with content is "test". Browser show result is "test". I am trying to commit this project again but result still is "test".
However, if I type index.php after my url "http://myaddress.com/index.php", I see my result which I would like. I have tried to config file "config.php" remove "index.php" in $config['index.php] = '' but nothing changes.
From the CodeIgniter's doc, check the "Remove the index.php file" on this page: http://www.codeigniter.com/userguide2/general/urls.html
And just to remember, have you enabled Apache's mod_rewrite?
Add .htaccess file with the following rule in root folder,
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
To make .htaccess work , you have to enable apache module mod_rewrite
If you have access to server, you can type the following command in the terminal (for linux servers, this example specific to ubuntu)
a2enmod rewrite
Restart apache2 after
/etc/init.d/apache2 restart
or
service apache2 restart
If you have not access to server, please contact server administrator.

.htaccess url rewrite not passing parameter - could there be apache settings somewhere that is preventing this?

Okay, so this problem has completely stumped me and the other devs I work with. Here is the rundown:
I have a local dev environment setup with Mac Apache2 pointed at /Users/myusername/Sites/
Within /Sites I have two folders, /site-1 and /site-2, both of which have virtual hosts pointed at them site-1.dev & site-2.dev. Both site-1 and site-2 are running local installs of PerchCMS.
Within /site-2 I have an .htaccess file which I am trying to set up a URL rewrite that takes the URL /detail/slug-here and translates it into /detail.php?s=slug-here
I have tried the following rewrites (at the suggestion of PerchCMS support) and both have failed to pass the s param:
RewriteRule ^detail/([a-zA-Z0-9-/]+)$ detail.php?s=$1 [L]
RewriteRule ^site-2/detail/([a-zA-Z0-9-/]+)$ /site-2/detail.php?s=$1 [L]
Additional info:
Yes mod_rewrite is enabled in apache... in the same .htaccess file it totally works if I do a simple rewrite like this...
RewriteRule dangerzone.html index.php
One odd behavior that I've noticed is that if I remove everything from .htaccess I can still pull up detail.php by pointing my browser at /detail/test-item-1...(yes I have restarted my server) so its behaving as if there is still some sort of rewrite in place and loading detail.php sans param just as it continues to do with the rewrite in place - is this a clue that there is something off somewhere else in my server config? Note, RewriteRule dangerzone.html index.php does NOT work once it is removed from .htaccess.
Have this code in your site root .htaccess (inside /site-2/):
Options -MultiViews
RewriteEngine On
RewriteRule ^detail/([a-zA-Z0-9/-]+)/?$ detail.php?s=$1 [L,QSA,NC]
Important is to turn off MultiViews options here. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Local Apache Server mod_rewrite/pretty links issue

I've had to move from testing on the live server, to testing locally on a virtual apache server. I've installed XAMPP just fine, downloaded and installed the wordpress files and the database. Everything looks great! The local version of my homepage is identical to the live version. There's only one problem: the homepage is the only page that works. When I click on one of the links i.e. the "about" page (http://localhost/wordpress/about/), I am redirected to the xampp control panel (http://localhost/xampp).
I have a good feeling this has to do with a problem with the "pretty links"/mod_rewrite rules. I made sure I brought over the .htaccess file, and it contains the rewrite instructions. The wordpress database has the proper permalink structure, and the httpd.conf file has the "RewriteEngine on" and the "FollowSymLinks" directives enabled. There has got to be some sort of rewrite problem here, although I am not ruling out something else stupid I might have done. Thanks for all your help!
-E
*Here is what the .htaccess looks like:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the httpd.conf, change the
DocumentRoot "/path/to/your/app/wordpress"
also
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/path/to/your/app/wordpress">
This should work, the path is absolute.
And do you have load the:
LoadModule rewrite_module modules/mod_rewrite.so
in httpd.conf??
If your server version works with a domain name, i.e: http://domainname.com is equivalent that http://localhost/wordpress the rewrite rules will be differents. post the rules here.
The problem is that wordpress does not believe in relative paths for some reason. There is an assumption that wordpress is running from the server root not a directory under the root (e.g. /var/www/wordpress will not work, but /var/www/ will).
The problem is with the .htaccess file they provide. It should re-write it to index.php and not /index.php. Change that line in your config and it will work.
What happens is that it tries to actually go to the default document root (in my case /var/www/index.php, which does not exist since I am using http://localhost/worpress which is an alias for ~/projects/worpress). You can check your error log and it will tell you where it is trying to look for the index.php file (which will return a 404 error).
I can go on a rant about how stupid it is that they do that and how bad the whole software design of wordpress is. But I will spare you that :).

Categories