CakePHP and .htaccess in shared hosting environment - .htaccess

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks

You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).

Are you sure the mod_rewrite module is enabled on your shared hosting?

Related

resolving index.php issue at url laravel htaccess

I know this question is asked alot and there are alot of answers on "how to resolve index.php issue in laravel".
However, I tried multiple ways in order to solve it from .htaccess on live dedicated server with WebsitePanel in order to remove index.php from URL. I tried a couple of ways however let me describe the issue here, index.php not only have changed the url, but also some of the css and javascript stuff are not loaded as well while most of them are loaded, CSS seems pretty fine but fonts are also changed.
It was working well at a shared host but here in a dedicated host it has alot of problems.
Is there a .htaccess code to solve this issue? and does index.php affects on CSS and is it normal?
my current htaccess is as follow:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>
You don't need to modify index.php or .htaccess. If you did this, revert to original files.
To remove index.php or public from URLs, you need to setup virtual host for Laravel project (there are instructions both for nginx and apache).
After that restart web server.
This is the most common problem in Laravel. When you upload your code to a webserver, your page will be in
www.web-something.com/index.php
So there are 2 things you should do,
1.Change the .htaccess file and also
2.Change the Virtual Host Settings in your server. Link :for setting up a virtual host in apache
After this you will be able to visit the directory just fine. Also about the CSS , problem , Its probably because of the virtual host settings. Itll get fixed up once you point everything to the right directory.
For IIS Windows Server, the .htaccess needs to be translated to web.config and this works like a charm.
here is the link:
How to enable modrewrite on IIS Web Server
In case Someone needed this in future!

Magento test envrionment redirect to live environment

dear sirs,
we are running a magento shop and our hosting company made us a dev environment, we want to use to upgrade the CE Version from 1.7.02 to 1.9.1. For this purpose a database was copied and the local.xml was edited correctly to connect with the test database.
But we have a problem, that the dev-subdomain (dev.domain.com) is not working. It redirects always to the live environment index.php (domain.com).
What should we do? Our hosting provider tells us the problem is in the .htaccess file in the live folder. The test environment .htaccess is empty.
My first idea:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/ [R=301,L]
Should we delete it or change it somehow? If i change both links to dev.comain.com the URL while visitng the site is correct, but the redirection fails and we get an error message.
If i add
#Alternate default index page
DirectoryIndex dev
Then neither the live nor the test index.php do work. So what could we try instead or additionally? The Rewriterules are on.
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
Additionally we have this one in our .htaccess
############################################
## default index file
DirectoryIndex index.php
<IfModule mod_php5.c>
Just deleting or renaming the .htaccess does not work neither. It just still redirects to the live environment.
I will be thankful for every hint.
Best Regards
Dimitri Petrik
You need to changed base URL stored in the database. Open core_config_data table and look for following rows:
web/unsecure/base_url
web/unsecure/base_link_url
web/unsecure/base_skin_url
web/unsecure/base_media_url
web/unsecure/base_js_url
web/secure/base_url
web/secure/base_link_url
web/secure/base_skin_url
web/secure/base_media_url
web/secure/base_js_url
web/cookie/cookie_path
web/cookie/cookie_domain
You probably only have to change web/unsecure/base_url and web/secure/base_url
And forget about .htaccess redirect.

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

mod_rewrite and GoDaddy

I really have only a fair idea of what I am doing. Sorry.
This is what I did to rewrite URLs like these:
http://example.com/foo/bar/news/1-category-name/2-item-name
http://example.com/foo/bar/news/1-category-name
into these:
http://example.com/foo/bar/news.php?newsID=2
http://example.com/foo/bar/news-categories.php?categID=1
respectively
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /foo/bar
RewriteRule ^news\/([^\/]+)/([0-9]+)-([^\/]+)$ news.php?newsID=$3
RewriteRule ^news\/([0-9]+)-([^\/]+)$ news-categories.php?categID=$1
</IfModule>
But whenever I try this URL:
http://example.com/foo/bar/news/16-news-category-1/11-title
It always returns a 404 error:
The requested URL /foo/bar/news.html/16-news-category-1/11-title was not found on this server
Why is it trying to find news.html? What am I doing wrong?
I don't know if this is relevant but example.com is virtual (I really don't know the term). The actual files can also be accessed via http://real-domain.com/qux/. So you'd do http://real-domain.com/qux/foo/bar/news/1-category-name/2-item-name to get to 2-item-name.
Does it also help to say that this script actually runs on my development machine?
Development:
PHP v5.3.5
Apache v2.2
Live:
PHP v5.3.6
Apache v2.2
You this code in your .htaccess:
RewriteEngine on
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$4 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$3 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
so when someone goes to:
news/11-category-12 or
news/11-category-12/ or
news/11-category or
news/11-category/
it goes to: news-categories.php?categID=11
and when someone goes to:
news/11-category-12/1-title or
news/11-category-12/1-title/ or
news/11-category/1-title or
news/11-category/1-title/
it goes to: news.php?newsID=1
Also, make sure the .htaccess is at the root of the public_html folder as well of news.php and news-categories.php

htaccess for cakephp [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.htaccess for cakephp
I use this code for htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Inside this folder,
root/
app/
app/webroot
But not work
My live path is http://www.jacksonwebservices.co.uk/
you should be running with the default cake supplied .htaccess files. there is nothing wrong with them for the most part. it seems like the .htaccess files are not readable by the webserver.
check your logs for more info.
Do you have that same .htaccess file in each of those directories? You need a different one in each of them. See http://book.cakephp.org/#!/view/917/Apache-and-mod_rewrite-and-htaccess for details.
I am guessing you are having the same Rewrite base problem that I recently had, put this in your .htaccess instead:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Sometimes it doesn't work without the 'RewriteBase' line at the top.
EDIT: DO AS JUHANA SAYS: Make sure you have the correct htaccess files in the correct locations. They are all different. If it is as you describe, webroot is redirecting to itself redirecting to itself redirecting ...
Does your website have mod_rewrite enabled?
Create a file that contains just this:
<?php
phpinfo();
?>
and save it as phpinfo.php in your document root (public_html, www or whatever)
Navigate to that page (http://www.jacksonwebservices.co.uk/phpinfo.php) and search the page for 'rewrite'. If you can't find it it's not enabled and CakePHP will not work in the default mode. See the manual for alternatives: http://book.cakephp.org/view/917/Apache-and-mod_rewrite-and-htaccess
You may need to contact your hosting to get it enabled or to find out how to do it yourself.

Resources