Getting Symfony2 to Work on GoDaddy without app.php - .htaccess

I got my Symfony site installed on my GoDaddy production sever. It works fine when I use the url www.amcolan.info/Symphony/web/app.php/index. I want it to set it up to work as www.amcolan.info/index.
I altered the domain to point to the folder amcolan/Symfony/web via a GoDaddy control panel. It used to point to /amcolan which contains the working version of my site. After I got that set up, I installed the following .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/app_dev.php - [L]
RewriteRule ^/app.php - [L]
# Fix the bundles folder
RewriteRule ^bundles/(.*)$ bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
#RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
I got the code from another related question on this site and modified to my purpose. The original was intended to live in the Symfony directory. I then cleared the production cache and attempted to access a page. It resulted in an Internal server error. Are there any errors in my code? You'd think this would be well documented by Sensio as I imagine 99% of all implementations would have to do this. Now I'm just getting bitter.
As suggested, I tried the following code that came with Symfony:
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_vhost_alias.c>
RewriteBase /
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I also tried:
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
#RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I got the same error as before with both. To make sure I was getting to the directory, I added a index.php file to it and I was able to access it.
Update 2
After rooting around some more about goDaddy specific issues, I found a post on a goDaddy forum saying the RewriteEngine is already on. I deleted that code without affect. I then decided to try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://www.amcolan.info/app.php/index [QSA,L]
That got it to work although I suspect not correctly. I had first tried it without the index after app.php/. That got me into symfony, but generated a get error. It appeared to be because of a null argument so I added the index. So, regardless of what someone might enter after www.amcolan.info, it's going to go to the index. Once you are on a Symfony page, you can navigate to other pages in the site. So now I have three new questions:
Any idea to where the web server is pointing when it reads the .htaccess file? You would think in the /web directory as that's where the file lives. Since just specifying app.php instead of the full path didn't work, it must not be the case. Would it be the base of my site?
After the successful redirection of www.amcolan.info, the resulting displayed URL is www.amcolan.info/app.php/index. I'd like to not see the /app.php in the URL, but I suspect that's not possible in as much as it is the actual destination. Is that a correct assumption?
How do I get www.amcolan.info/somepage to go to www.amcolan.info/app.php/somepage rather than the hard coded index?
Update 3
I thought I was stuck, but then I tried:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php/index [QSA,L]
That got rid of having to use the full URL and now the destination pages no longer display the app.php. I have a new problem: just specifying www.amcolan.info causes the get error mentioned above. Specifying www.amcolan.info/somepage no longer takes me to the index, but to the specified page. Stay tuned, I may be able to solve my last problem with a little more digging.
Update 4
I fixed the last problem by adding the following to my routing file:
nopage:
pattern: /
defaults: { _controller: ZetchoAmColAnBundle:Default:index }
requirements:
_method: GET
I think I'm a happy camper now.

index action is not necessary. You can easily configure any action for root routing as well.
Here is my full .htaccess file on GoDaddy that finally works. It works only for prod config (app.php), app_dev.php is not working well, but that is OK for me since it is used for production environment.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php/ [QSA,L]
</IfModule>

Related

url redirection in the default .htaccess file

I would like to map "http://www.example.com/abc" to "http://www.example.com/test/abc" for having the shortest route possible. I am using pyroCMS for my users and content.
the default pyrocms file:
# Multiple Environment config
# Set this to development, staging or production
# SetEnv PYRO_ENV production
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
# disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting
Options -MultiViews
RewriteEngine on
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/.*/(vendor|composer\.json|composer\.lock|system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
I would like to add this rule to the file:
RewriteRule ^([a-z0-9_]+)$ test/$1
To rewrite "BASE_URL/abc" to "BASE_URL/test/abc"
However,
i tried many positions as to where to put this RewriteRule, my website keeps giving a "Page Missing".
Is my RewriteRule ok? And where do i insert it?
PyroCMS has built-in modular routing ability. see here:
http://docs.pyrocms.com/2.2/manual/developers/basics/modular-routing
If your "http://www.example.com/abc" refers to a custom module,then, you can add a file named "routes.php" in a in config folder of your module.
the folder construction should like this :
addones/shared_addons/modules/your-module/config/routes.php
OR even you can edit the core route config file located at system/cms/config/routes.php and add this line or whatever your routing rules are:
$route['abd'] = 'test/abd';
OR more even, at your control pannel there is a redirect module that you can add redirections.
It all depends on what your rule is supposed to do and how it is supposed to interact (or not interact) with the rest of your site. And considering your entire htaccess file is mostly commented out code (which I removed to make it halfway readable), you just want to place it under RewriteEngine On.
However, since it blindly routes everything into test you need to add a few conditions and make it something lilke:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/test%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/test%{REQUEST_URI} -d
RewriteRule ^([a-z0-9_]+)$ test/$1 [L]

Codeigniter and .htaccess file to ignore index.php

So I'm having a weird problem with .htaccess file and codeigniter. I have a wamp server on my local machine and there it works as expected. I have folders like that wamp/www/my_app and in my_app folder i have .htaccess file like that:
ErrorDocument 404 /index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
And in mine config.php gile i have:
$config['base_url']='';
$config['index_page']='';
$config['uri_protocol']='AUTO';
So i tried uploading that project to debian server on link like apps.myserver.com/my_app. I put my app to folder var/www/my_app. But the trick is that it doesn't work.
I have tried changing uri_protocol to all 5 options but no change. I also tried putting .htaccess file to var/www instead of var/www/my_app but no change either.
I keep getting that stupid 404 Not Found error when i try to access controlers without index.php prefix.
Any ideas?
EDIT: I checked phpinfo on server and found that mod_rewrite is in loaded modules.
The mod_rewrite module can have a couple different extensions. Your Debian server might use mod_rewrite.so instead of mod_rewrite.c.
That said, if you know mod_rewrite is enabled, and your application isn't being widely distributed and needs to check for it, you can safely eliminate the if checks.
You mentioned commenting out everything except lines 3 and 7 -- you commented out the RewriteBase definition, which broke stuff.
Try something simple, and work from there:
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Also, one variation you can do if an .htaccess is being weird, is to change everything after index.php to a query string. Note the ? here:
RewriteRule ^(.*)$ index.php?/$1 [L]
You may or may not to change the uri_protocol config setting in CodeIgniter. My guess is you specifically won't, but it's info for others who are having .htaccess issues.

Controller does not open in CodeIgniter

I have three controllers in CodeIgniter application - i, login and test.
All controllers perfectly work with /APP/index.php/ path - I can open /APP/index.php/i, /APP/index.php/login and /APP/index.php/test.
Controllers i and login work without index.php as well - /APP/i and /APP/login (I have a modified .htaccess file).
Controller test does NOT work without index.php - I get 404 error when I open /APP/test.
i is the default controller, but login is not default and it works (I thought it could be the problem).
When I added the 4th controller it also didn't work without index.php.
It gets even more weird - sometimes I can open /APP/test/some_function (and sometimes I cannot) and after this I can even open /APP/test. But then I cannot open it again this way. index.php way works all the time. Test controller has a really simple code...
So my question is what can possibly go wrong here and how can I make my controllers accessible without index.php?
Thank you very much for your help.
Below is my .htaccess file, I think the problem can be there:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /APP/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I now understand where the problem was, thanks to #w0rldart suggestion.
Actually, when you access the controller without index.php file, the main application folder becomes case-sensitive (APP in my question).
As I have a much longer application folder name and it has both lower and upper case letters, I just had it typed with one letter in the wrong case. For the default controller it does not matter and other controllers were accessed via the links where the case was correct.
And as test was accessed directly, this wrong case was giving me 404 error.
Via index.php path the case of the main application folder doesn't matter.

.htaccess help shortening a url

i have been working on setting up a url shortener with codeigniter i have everything working great and it works now with shortened urls like below.
http://example.com/shorten/i/znAS
ok what am looking to do is shorten it just to the i with my .htaccess access i am a complete newbie with .htaccess and have no idea how to do this is have been following this example here. http://briancray.com/posts/free-php-url-shortener-script/
which uses
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^shorten/(.*)$ shorten.php?longurl=$1 [L]
RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L]
</IfModule>
Above is not really relevant for mine as its code igniter based. ok so shorten is my controller and i have a function within called i,
i have tried various combinations but nothing has worked for me yet below is my .htaccess.
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shorten/(.*)$ shorten/i/=$1 [L]
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
whats there is currently breaking the website at the moment just looking and google at the mo but thought i would also add a post here as well thanks
With CI (or any framework for that matter), it is best to never touch the .htaccess file, unless you really need to. Take a look at the documentation with regard to working with the routes.php file in your application/config directory.
Try this route setting in the array:
'shorten/(.+)' => 'shorten/i/$1'
Please let me know if you have any problems with this.

Routing To A Folder In Cakephp's App/Webroot

I'm aware that there are a few questions on this subject already. I've trawled through them and can't make any of the proposed solutions work for me... maybe someone can help my specific problem?
I have a folder, parallax, in my app/webroot, containing index.html and associated files. This can be accessed just fine at /parallax/. However, if I try to access it at /parallax I get redirected to /app/webroot/parallax/, and ideally I'd like to suppress this behaviour.
Refactoring the whole thing as a CakePHP controller action isn't ideally something I want to get into (though if it might be simpler than I expect, let me know). The routes file doesn't as far as I know allow routing to a file in app/webroot.
The other port of call would seem to be the .htaccess file. I tried adding a rewrite rule:
RewritRule ^parallax$ parallax/index.html
or variations thereof, but the best I can get here is a page with broken images (whatever I'm ending up with, it doesn't seem to be able to find the images in the parallax/images subfolder any more).
Can anyone clear up my confusion and help me find the best route to /parallax giving the same result as /parallax/ does?
Please try the below .htaccess code in your root directory not in app directory.
<IfModule mod_rewrite.c>
RewriteEngine on
Rewriterule ^parallax/.*$ - [PT]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This should help you. What ever request start with parallax will be skipped by the .htaccess rule. And rest of the things will work as it is.
.htaccess root thanks to Anh Pham for this link it works perfectly http://www.balistupa.com/blog/2010/08/how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp/
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-d
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I tried to reproduce the situation but its working corretly for me. I'm using cakePhp 1.3 and both urls send me to index.html:
http://localhost:5013/parallax/
http://localhost:5013/parallax
My guess is that there's something weird on your .htaccess (the one located at /app/webroot/). Mine is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Basically, it tells the server that if the requested url is not a file (!-f) nor a directory (!-d), it will redirect the whole url as a parameter to /webroot/index.php , so cakephp will parse the url and call the controllers and all that..
Hope this helps
You should be able to put the parallax folder with a static index.html inside the app/webroot folder and have it be accessible by default at the /parallax/ url.
If you use relative paths you can even have you img/css for that page local to the folder and skip the usual cakephp paths entirely. No htaccess needed.

Resources