Symbolic links not working on apache 2.2 - php

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

Related

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!

File not found with .htaccess file on Apache server

I have this .htaccess on my Windows dev machine and everything works fine
RewriteEngine On
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/webserv/$1 [R=301,L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2 [L,NC,QSA]
When I upload it on my Centos server I get the error
404 The requested URL path_to_script/login.php was not found on this server.
I cannot understand why this is. The file is definitely there and I gave permissions 777.
I have checked if the .htaccess is actually used by adding rubbish in it and getting an internal error (500) which means that it is working.
Also when I use .htaccess to make restrictions on IPs that have access to the directory it works. mod_rewrite is loaded as shown in the phpinfo() I have tried.
I am at a loss here.
EDIT
I noticed that it tries to search in the base_path appending it to the root path e.g.
/path_to_script/path_to_script/login.php
And that is why it fails. How do I solve this?
I finally solved it but in a way that I am not sure I like. At least it works. If someone has a better solution I would be glad to see it.
RewriteRule ^login/([0-9]+)/([0-9]+)$ http://host/webserv/login.php?par1=$1&par2=$2
The reason I don't like this solution is because I does not give a pretty url. It just redirects.
I still do not understand why I get the root directory appended to the request if I instead write:
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2

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 :).

.htaccess not working

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.

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