Routing To A Folder In Cakephp's App/Webroot - .htaccess

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.

Related

Modify .htaccess for codeigniter URLS

I am trying to remove the index.php from the url in codeigniter. Rewrite mod scripts are all over the place but I can't find the .htaccess file!! I tried looking in the root directory and everywhere else, but no luck.
From what I read it should be in application folder and when I go there i find the .htaccess file and all it has is deny from all. This is not the same content every one else is sharing online before modification.
Please advise.
Actually you don't find it; you create it along side with your index.php file with this contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php,
images, and robots.txt is treated as a request for your index.php
file.
Reference.
The solution is as follows ( for future references)
Create the .htaccess file in the root of the codeigniter application (where you got system, application, etc folders).
Paste this code in it:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Open config.php and change index = "index.php" to "". Things should work now.

Getting Symfony2 to Work on GoDaddy without app.php

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>

fuelphp htaccess for multiple app directory not working

I have a directory structure like below.
public_html/
/abc/
/xyz/
/pqr/
there is a index.php in each these directories, abc,xyz,pqr.
now whenever is there any request like domain.com/abc/def/ghi should be rewritten to domain.com/abc/index.php/def/ghi
domain.com/xyz/def/ghi => domain.com/xyz/index.php/def/ghi
domain.com/pqr/def/ghi => domain.com/pqr/index.php/def/ghi
What should be the .htaccess file and where it should be placed?
I have .htaccess file in each directory(abc,xyz,pqr) like below, but it is not working. it is showing 404 page not found. Please guide me to handle all these rewrite conditions.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
But this is not working... If this is right .htaccess then please tell me if there is any other server side problem. I am setting up this on CentOs server.
You will probably need a RewriteBase /abc to deal with the subfolders.
I had problem with my directory access, I was needed to update the access for content directory(domain.com) in apache config file(httpd.conf)

.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.

.htaccess flat link

I want to to use flat links like this:
http://somedomain.com/about-us
http://somedomain.com/products-list
http://somedomain.com/product/item
Thus I've used the mod_rewrite rules like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z-]+)?$ /index.php?page=$1 [L]
RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]
</IfModule>
The first two links are working fine. But whenever I visit the third type of links the images or the css or any js script that are linked as relative path eg. <img src="images/image.jpg"> and About Us.
The browser thinks it is in http://somedomain.com/product/images/image.jpg and http://somedomain.com/product/about-us.
The correct path should be http://somedomain.com/images/image.jpg and http://somedomain.com/about-us
And thus files with relative links are not working.
How to fix this issue? I don't want to use full path instead of relative for all linked files. Please suggest a way by doing some tweaks in the .htaccess
Try escaping your slash:
RewriteRule ^([0-9A-Za-z-]+)\/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]

Resources