Cake 2.+ on shared hosting - 404 error - apache

Since 2 days I have been trying to get my cake app working (using German 1&1 hosting). The desired address is: http://www.bzalewski.de/k/front. If you open it, you can see, it's there but without images and css. Also this: http://www.bzalewski.de/k/front/art/discover doesn't work (but it does locally with XAMPP. There is no routing, just ArtController --> public function discover()).
I followed the instructions from this article: http://bakery.cakephp.org/articles/tim_m/2007/09/20/500-errors-with-1and1-hosting-apache-1-x
My three .htaccess look like this:
./.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) k/front/app/webroot/$1 [L]
</IfModule>
./app/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) /k/front/app/webroot/$1 [L]
</IfModule>
.app/webroot/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /k/front/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
I would appreciate any help to:
make controllers work (art/discover working)
make images and other stuff in the webroot directory work
Just to mention it: my local XAMPP installation works with standard .htaccess files without any problems.

Try adding this line in the root .htaccess (the htaccess in /k/front/ folder) after RewriteEngine On:
RewriteBase /k/front/
Edit : I did not see that you put /k/front/ everywhere in the htaccess
Then add RewriteBase / with you version of the htaccess
OR add RewriteBase /k/front/ with the default htaccess (without /k/front/ in the RewriteRules )

Related

Getting 404 error when viewing CakePHP 3 app on 1and1

When I attempt to hit my site which is at mydomain.com/subfolder, I get a 404 (from Apache).
/subfolder/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/subfolder/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To confirm that mod_rewrite works, I added this in the /subfolder/.htaccess file which promptly redirected:
Redirect 301 / http://other-domain-owned.com/
So, .htaccess are live and mod_rewrite works.
On my development environment, I was able to make the site work in the same /subfolder by symply enabling .htaccess files for that folder via a Directory directive.
Some tutorials say to add RewriteBase / but this didn't help.
Instead of RewriteBase, you can also use an absolute path. Additionally, the first two rules can be simplified to one
RewritRule ^(.*)$ /subfolder/webroot/$1 [L]
Similar the second part
RewriteRule ^ /subfolder/webroot/index.php [L]
Finally, Redirect and RewriteRule are from different modules. So, if one of the directives is working, this is no proof for the other one working too.

Silex rewrite, one.com

I am using this apache rewrite, when i am on my local machine.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
But after i uploaded it, to my host i get server error. They told me they dont support Options, but i can't get it working without that.
I am trying to route my Silex installation, so its /web/stats/ instead of web/index.php/stats.
I found this example for Codeigniter http://www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/
Anyone know how to make it work with Silex?
Same problem at some hosters. If your server has installed Apache >= 2.2.16 you can use the FallbackResource command:
FallbackResource /index.php
in your .htaccess instead of
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
See also Apache’s fallbackresource: your new .htaccess command for more information.

Allow URLs without any extension with url rewriting, like exemple.com/forum

I need to allow urls like http://example.com/forum on my website.
Here is my .htaccess :
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z-]+)$ /$1.php [L]
Currently, I get a 404 error.
If I change ^([a-z-]+)$ /$1.php [L] to ^([a-z-]+).html$ /$1.php [L], and my url http://example.com/forum.html, it works.
I want something like stackoverflow, http://stackoverflow.com/questions
EDIT: It works with WAMP in localhost, but on the website, it doesn't.
What's missing?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# add .php file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.+) /$1.php [L,QSA]
I have added Options -MultiViews -- can make a big difference on some configurations (possibly your case).
Rule is now also checking if such .php file actually exist. If not -- no rewrite occurs.

.htaccess to mask url and redirect domain name to subdirectory

Hi folks
I'd appreciate some .htaccess advice.
I have two wordpress installations. "A" which is in my ISP's Linux server root directory and "B", which is in a subdirectory of the same server called "directoryB".
Actual structure is:=
A.com
A.com/directoryB/
I own two domain names A.com and B.com. I want people to use the address B.com when accessing everything on directoryB, not A.com/directoryB/.
I want to leave the "real" "A" alone - no redirections!
I have been assured this can be done using the .htaccess file, but I've failed so far!
I have managed to "mask" the home page of "B" using cPanel, but it reverts back to A.com/directoryB/ once you move away from the home page. I'm also not sure if the .htaccess ought to be in the root or subdirectory.
All I want is to mask the A.com/directoryB/ with B.com/ every time it appears on the address bar......
Thanks in advance for any help!
Put this in a .htaccess file in directoryB and see if it works:
RewriteCond %{HTTP_HOST} !^B.com$ [NC]
RewriteRule (.*) http://B.com/$1 [R=301,L]
Put this in .htaccess in your root directory -
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect permanent /directoryB http://B.com
</IfModule>
The htaccess in public_html is:-
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect permanent /directoryB http://B.com
RewriteRule ^test/([^/]*)/$ /test/login/?id=$1
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options -Indexes
=============== this is the htaccess from "directoryB"
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]
</IfModule>
# END WordPress
Options -Indexes

Beginner Apache URL Rewrite Question

I'm just trying to figure out if I'm on the right path - additional details on rewriting the URL in my example would be appreciated.
I have installed a CMS program and would simply like that www.example.com be pointed to www.example.com/cms. I just want to know if URL rewriting through apache is the best way to accomplish this?
Thank you.
Just redirecting http://example.com/ to http://example.com/cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewritRule ^/?$ /cms/
</IfModule>
Redirecting all urls which otherwise would've 404d to start with /cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>
Redirecting all urls to /cms/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ /cms/$1 [L]
<Directory /var/www/html/cms/> #change this to the correct path
RewriteEngine Off
</Directory>
</IfModule>
That's definitely the approach I would take. I'm going to assume you're using Apache, though this can easily be done with IIS as well. You'll need to edit your .htaccess file in the root directory to do this using mod_rewrite.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>
This should work for what you're after. Change "cms" to whatever directory you want to rewrite to.