Mod_ReWrite doesn't work on cakephp - apache

I have recently deployed CakePHP however mod_Rewrite is not currently working:
I have the following in my apache2.conf
<Directory "/path/to/the/app">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
i have run
sudo a2enmod rewrite
which stated the module is already enabled and i have also checked the .htaccess file which has
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
has anyone got any other ideas as to why mod_rewrite isn't working?
Please note i have restarted apache with no sucess

There must be 3 .htaccess files in these locations
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
Do you have them?

Turns out mod_rewrite was working, however I was using cakephp 1.3 which doesn't detect if the mod_rewrite works but applys a CSS style which wasn't applying to the div. it works now anyways

Related

.htaccess mod_reqrite not working

So I am trying to use mod rewrite in apache2 to make it going from this link:
http://website.com/site/player.php?name=_Joosh
to using
http://website.com/site/u/_Joosh
Here is what I have tried so far in my .htaccess file I have.
RewriteEngine On
RewriteRule ^u/([A-Za-z0-9-+)/?$ player.php?name=$1 [NC,L]
And I have checked rewrite is an enabled mod in apache and I have added
Options FollowSymLinks ExecCGI
to my vhost file. Any help please?
You can use the following rule in your /mainpvp/.htaccess
RewriteEngine On
RewriteRule ^mainpvp/u/([A-Za-z0-9-+)/?$ /mainpvp/player.php?name=$1 [L]

mod_rewrite all to index.php in one environment

I know there are a million of questions about this, but I've tried the solutions in other questions and haven't got it to work in my case. I'm trying to redirect everything to index.php:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This works in my local environment, but in my staging environment it fails and I get a 404 error. I've checked that mod_rewrite is enabled with phpinfo(). I've tried changing a few things like using ^(.*)$ instead of ^ and using /index.php instead of index.php
What else could be the problem?
Figured it out. It was a problem with the configuration of apache. Whoever set it up for the site I'm working on did it like this in the site's .conf file:
<Directory "/data/path/to/directory">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
# and a bunch of rewrite rules...
</Directory>
The AllowOverride None prohibits the use of .htaccess. In our local and development environments, the directory structure is different, so this code doesn't even get applied. That's why the .htaccess was working.
To solve the problem I'll either have to change the line mentioned above to AllowOverride All or add another configuration for the website I'm working on like the one above that does what I wanted to do with .htaccess.
Problems like this shouldn't come up for anyone if their environments are configured appropriately, but if anyone does run into a similar situation, check the configuration of the site in apache!

default cakePhp .htaccess file does not work with redirection

I just installed an Ubuntu web server with apache2. I upload a CakePHP project. I also activated rewrite_mod.
# sudo a2enmod rewrite
When navigating to www.mysite.ch/pierre/contacts it states:
Not found
The requested URL /contacts was not found on this server.
In my local webserver, it works and I can see the contact page
If I remove my project and add a file phpinfo.php with the function phpinfo(), it show information about the server configuration and I do not have a message "not found"
I suspect that my redirection does not work.
What do you think?
Which are the basic step to make an Apache2 server working with an .htaccess file?
Here are is my .htaccess file (it is the default cakephp file, I have not changed it)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Here is my httpd_conf file
<Directory /var/www/vhosts/metauxch/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Do you have some idea?
Change AllowOverride None to AllowOverride All in httpd_conf file
Enable mode rewrite,
sudo a2enmod rewrite
restart apache,
sudo /etc/init.d/apache2 restart
I am sorry, I forgetten to write but I did it
sudo a2enmod rewrite
sudo servive apache2 restart
This is done.
I also change this AllowOverride All
The probleme, now is when I enter
http://eflumpc38.epfl.ch/pierre/contacts
It state that te controller pierre (CakePHP) is missing. While pierre is the root and contacts is the controller.
Second point, when I clink on the Contact (root/contacts/)
I have a such URL
http://eflumpc38.epfl.ch/vhosts/pierre/httpdoc/contacts
instead of
http://eflumpc38.epfl.ch/pierre/contacts
Does some thing is wrong here
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
allow from All
</Directory>
When I upload the same CakePHP projet on my usual provider, I do not have this issue.
Thank
try this solution.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
CakePHP app directory (will be copied to the top directory of your application by bake):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
CakePHP webroot directory (will be copied to your application’s web root by bake):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>

Making pretty permalinks work in WAMP

I am not able to switch to pretty permalinks in WAMP. Changing to any form other than default gives 404 error.
I have switched on the rewrite_module in Apache. I Googled the problem and found that following changes should be made to httpd.conf file. My httpd.conf file stands as
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
I also checked that the .htaccess file is getting created. It reads as
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /vit%20web/events/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /vit%20web/events/index.php [L]
</IfModule>
# END WordPress
All you need to do is turn on the mod_rewrite in the wamp settings tab.
Click Wamp -> Apache -> Apache Modules -> rewrite_module
If you select that then turn on %postname% it should work
Did you reboot Apache after editing httpd.conf?
A bulletproof check for mod_rewrite is to remove the <IfModule>...</IfModule> tags and try running WordPress - if you get a 500 Server Error, mod_rewrite isn't installed.
Also I would recommend changing <Directory /> to <Directory "C:/path/to/server/root"> (note the forward slashes too, even on Windows).
And the deny order should be switched if you're only on a development server;
Order allow,deny
Allow from all
The problem may be:
Whenever you have permalinks in subfolder of your main www folder (i.e.
RewriteBase /subdirectory/
you may need to have a .htaccess file in your main c:\wamp\www folder too.

Redirect Using htaccess

I am trying to redirect /folder to / using .htaccess but all am I getting is the Apache HTTP Server Test Page.
My root directory looks like this:
/
.htaccess
-/folder
-/folder2
-/folder3
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ folder/$1 [L]
What am I doing wrong? I checked my httpd.conf (I'm running Centos 5.3) and the mod_rewrite library is being loaded. As a side note, my server is not a www server, its simply a virtual machine so its hostname is centosvm.
Addition: I have found that the mod_rewrite module is loaded, but none of my .htaccess redirects seem to be working.
Addition: My httpd.conf directory directive looks like:
<Directory />
Options FollowSymLinks
#AllowOverride None
</Directory>
What does you AllowOverride say? (see: http://httpd.apache.org/docs/2.0/howto/htaccess.html)
And that would bring us to requiring this in (virtual)host/directory settings:
AllowOverride FileInfo