Cakephp redirection problem - php

I have a problem of too many redirection in one cakephp site.
Here is the site: http://pexinxas24.com/
This domain is pointed to root of the site and not to app folder.
Here is the code which is placed in htaccess of the root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Here is the code which is places in the htaccess of the app folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
I am not getting any typs of PHP or cakephp errors.
This site always redirect to the root of the site. Whole code was working properly on old server. I have just changed the server and getting this error.

Looks like your are using Amazon-EC2 right? ;)
Well, probably you aren't redirected for the next reasons:
mod_rewrite it isn't enabled: Look inside of your httpd.conf, you should have the next line uncommented:
LoadModule rewrite_module modules/mod_rewrite.so
You haven't enabled override in htaccess: Look inside of your http.conf for the
directive "Directory", inside you should have something like this:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
The most important line of the previous code is AllowOverride All, on amazon instances is set to AllowOverride none by default, so you should change it to All, after that you must restart your apache server to reflect changes.
Hope it helps.

This is an old thread.
Probably if you understand about apache2 Ismael's answer is quite enough, but if you're a newbe in this subject as I am, might be useful saying that in apache2 nowadays you should "replace" the part one where he says
mod_rewrite it isn't enabled: Look inside of your httpd.conf, you should have the next line uncommented: LoadModule rewrite_module modules/mod_rewrite.so
for copying rewrite.load from mods-available to mods-enabled:
cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

Related

mod_rewrite redirects don’t work as expected

I have two problems actually:
First, I’m trying to redirect several short URLs to a single page with more actions, like this:
RewriteEngine On
RewriteRule ^/login?$ ^login.php?action=login&next=$1 [L]
RewriteRule ^/reset?$ ^login.php?action=reset&next=$1 [L]
This is being written in the .conf file inside <Directory>. The problem is that the first rule gets executed, while the second doesn’t and I can’t figure why.
I also tried writing them like this:
RewriteCond %{REQUEST_URI} /login$
RewriteRule ^login.php?action=login&next=$1 [L]
RewriteCond %{REQUEST_URI} /reset$
RewriteRule ^login.php?action=reset&next=$1 [L]
I should probably mention that login.php does not reside in the root directory, but in different subdirectories.
What am I doing wrong and how can I fix it?
The second issue I have is that if I put an .htaccess file inside the root directory, the rules in the .conf file don’t get executed anymore.
Inside the .conf file I have these rules:
<Directory>
Options Indexes FollowSymLinks ExecCGI Includes MultiViews
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
</Directory>
Why is this and how can I fix it?
Just to extend on from my comments above. Place these rules in your site root .htaccess or in httpd.conf file:
Options -MultiViews
RewriteEngine On
RewriteRule ^/?login(?:/(.*))?$ subdir1/login.php?action=login&next=$1 [L,NC,QSA]
RewriteRule ^/?reset(?:/(.*))?$ subdir1/login.php?action=reset&next=$1 [L,NC,QSA]
Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

Permalinks in Wordpress not working

Recently I have updated PHP from version 5.3 to 5.5 on my web server.
Wordpress Permalinks was working prior to that, but now Permalinks has stopped working, and I have to use the default option which gives the page id in url.
Wordpress version is 4.0.1
Go to admin
Click Settings
Click Permalinks
Select Post Name (for clean permalinks) or default
Finally Click Save
This rewrites .htaccess and wordpress permalinks may work in most cases
if .htaccess is not created, make .htaccess with following
# 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
can you also confirm mod_rewrite is enabled in your server?
For some situations just resaving the permalink settings in Dashboard>Settings>Permalink>[postname]>Save Changes will refresh the .htaccess file.
If that is ignored, chances are that the .htaccess file is not writeable. In that case, check your apache.conf:
sudo vi /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride ALL <----(edit from none)
Require all granted
</Directory>
Then restart apache2 using:
sudo service apache2 restart
While there, be sure to double-check permissions and owner of the file:
-rw-r--r-- 1 www-data www-data 1668 Jan 8 04:34 .htaccess

Laravel 4 remove Index.php from URL

I need some help with laravel 4 application i need to remove Index.php from url i have tried the solution that has been mentioned in laravel documentation
Pretty URLs
Apache
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
any Suggestions :) ?
FOR LAMP SERVER
Try the following steps,
Activate the mod_rewrite module with,
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">`
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
this worked for me
<Directory "/var/www/html">`
AllowOverride All
</Directory>
uncomment 'LoadModule rewrite_module modules/mod_rewrite.so' in apache httpd.conf
in 'public' folder check .htaccess file (created by default)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have read long posts and threads but nothing works then i found this and it works for me.
The easiest way to do this (and the way I always use) is to open up your Command prompt or Terminal and cd into the main directory of your project then run "php artisan serve". That's it. You're done. Don't believe me? Check out http://localhost:8000 and admire your Laravel work.
http://michaelbrooks.co.uk/post/laravel-localhost-removing-public-index-php
just go to your apache settings folder, i use wamp so myne is
C:/wamp/bin/apache/apache2.4.9/conf/httpd.conf - file
// located on line 154 precisely...
#LoadModule rewrite_module modules/mod_rewrite.so
// to
LoadModule rewrite_module modules/mod_rewrite.so
restart WAMP and BOOM!.. it works.
mod_rewrite apache module may not be enabled by default. enable it and retry.
Try this:
a2enmod rewrite
And it will works

URL Rewriting not working (ubuntu13.10/apache2.4.6)

I need your help! (sorry for my bad english)
I try to do url rewriting in my localhost on Ubuntu13.10/Apache2.4.6 ...
I searched a lot of time on internet and problem is always here..
this is my .htaccess (I begin in url rewriting so I don't know if it's ok) :
RewriteEngine On
AllowFromAll All
RewriteRule home/ index.php?uc=home
and when I go to 127.0.0.1/mywebsite/home/ I have a 404 error.
My .htaccess is in : mywebsite/.htaccess
I activated url rewrite with "sudo a2enmod rewrite" and restarted apache.
I have no error in apache logs
I read solution who said I have to change AllowOverride to On in /etc/apache2/sites-available/default but I dont have /etc/apache2/sites-available/default file
I am lost...
Please, I don't know what to do...
After many tests : I think I have a problem of AllowOverride
You either need to specify the RewriteBase
RewriteBase /mywebsite/
RewriteRule home index.php?uc=home [L]
or add it to your rule
RewriteRule /mywebsite/home index.php?uc=home [L]
I think this is more like this :
RewriteRule is relative to the RewriteBase, so if your .htacess is in /mywebsite/ folder :
RewriteBase /
RewriteRule /home index.php?uc=home [L]
this way it should work, let me know ;)
So... If this is not working, let's start by the beginning.
Find httpd.conf
LoadModule rewrite_module libexec/mod_rewrite.so and AddModule mod_rewrite.c should be in there, and without comment mark (#)
In your .htaccess, there is :
# The server must follow symbolic links (this can help in some apache versions)
Options +FollowSymlinks
# RewriteEngine activation
RewriteEngine on
# RewriteRule
RewriteRule ^home$ index.php?uc=home [L]
This configuration works on my apache 2.2.22.
The truth is that
/index.php?uc=home [L]
points on http://127.0.0.1/index.php
instead of http://127.0.0.1/mywebsite/index.php
because of the DocumentRoot property. On a real domain, or /w a virtualhost pointing on /mywebsite/, /index.php?uc=home [L] should work.
Keep in mind that RewriteRule is relative to the DocumentRoot and RewriteBase can't resolves this problem.

htaccess url-rewriting not working with config setup

I'm on a win8 machine running XAMPP. I have a virtual host directory set up with a .htaccess file. I have been researching how to rewrite urls and I found the RewriteEngine module. In my httpd.conf apache file, the module was already enabled:
LoadModule rewrite_module modules/mod_rewrite.so
It seems like the next step was to update my .htaccess file like so:
php_value register_globals off
DirectoryIndex default.php index.php
ErrorDocument 404 /filenotfound.html
RewriteEngine On
RewriteBase /
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
RewriteRule ^Blog//Categories$ Blog/Categories.php [L]
RewriteRule ^Blog//([^/.]+)/?$ Blog/Posts.php?val=$1 [L]
I have followed a couple SO questions (config and rewriting w/ params), but am unable to get even the easiest rewrites to work. I have restarted apache a couple of times with no results.
While I'm here, this is my folder structure boiled down to everything relevant:
root
.htaccess
Blog
AuthorPanel.php
Categories.php
Post.php
Posts.php
Default.php
About.php
Work.php
And these are the rewrites I am looking to achieve (I have already tried most of them):
site.com/Default.php => site.com/Home
site.com/About.php => site.com/AboutMe
site.com/Blog/Categories.php => site.com/Blog/Categories
site.com/Blog/Posts.php?id=3&val=Android => site.com/Blog/Android
site.com//Blog/Post.php?id=4&title=Working+with+ActionBar => site.com/Blog/Working-with-ActionBar
Update 1 In httpd-vhosts.conf I even tried using the RewriteEngine on and rewrite rules, with no luck either:
<VirtualHost *>
DocumentRoot "C:/Users/ben/Documents/PHP/benWIT"
ServerName benWIT.local
<Directory "C:/Users/ben/Documents/PHP/benWIT">
RewriteEngine on
Order allow,deny
AllowOverride all
Allow from all
Require all granted
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
</Directory>
</VirtualHost>
Since you are using htaccess then you will need to make sure AllowOverride is set to All in your httpd.conf file:
AllowOverride All
This will allow you to use htaccess files. Having said that, as a general rule you don't want to use htaccess files or enable AllowOverride if you have access to the apache config files simply because it will use more resources to search the directory and find the htaccess files etc. Placing the changes into the httpd.conf file or conf.d/example_host.conf is much better.
One other note, mod_rewrite is over used and is really overkill for most purposes. I would advice you use mod_alias (see http://httpd.apache.org/docs/2.2/mod/mod_alias.html) instead. I should point out this can only be use in server configs or virtual hosts, so it will not work in a htaccess file. But it should be given preference should you have the choice between the two.
Alias /home /default.php
Alias /aboutme /about.php
Alias /work /work.php
AliasMatch /blog//([^/.]+)/? /blog/posts.php?val=$1
.. and so on.
Here is a good read on when not to use mod_rewrite:
http://httpd.apache.org/docs/2.2/rewrite/avoid.html

Categories