I have a question, where should I put framework folders on live server? That's my first application in Zend Framework 2. On localhost everything seems to work fine, I wanted test it on live server and I got confused.
home
home/username
home/username/public_html
I put everything in public_html with copied .htaccess from Zend's public folder. So my structure looks like this:
home/
home/username/
home/username/public_html/
config/
data/
module/
public/
vendor/
.htaccess
init_autoloader.php
But I can't access my application in www.mydomain.com/ I have to use www.mydomain.com/public
I think the problem is with .htaccess, so here it is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
php_flag eaccelerator.enable 0
php_flag eaccelerator.optimizer 0
I tried add RewriteRule ^(.*)$ /public/index.php [NC,L] but it didn't change anything.
Is it a proper structure of application on live server?
Where should I keep vendor folder?
I usually clone my application to /home/username/application and symlink /home/username/public_html to application/public
Your location of the vendor folder is fine!
Related
I made a router using a /public folder.
This folder contains my index.php that routes every route i need plus some css, js and stuff.
Using Wamp and a command line i can change the root folder to be /public
php -S localhost:8000 -t public
My job's done and i want to upload my newly created website to a server.
And... Yeah, i need to configure a .htaccess.
So, after some researches i found a "universal" solution:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]
I needed to change the last line:
RewriteRule ^(.*)$ /public/index.php [L]
Everything routes perfectly, the only problem is that css/js doesn't load. Looking at the superglobal $_SERVER it appears that
["DOCUMENT_ROOT"]=> string(15) "/home/routerphp"
does not contain my public folder.
I also tried:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php
With the same result.
I'm kinda desperate. Any help is appreciated.
Sometimes you just need to take a break and clear cache.
Everything is alright...
First I apologies posting similar questions in this forum which already have 1000 or more similar topics. Unfortunately I couldn't yet find a solution so I thought it is worth posting here.
My issue:
We have Zend Framework installed in our web server and all non-file, non-directory requests are routed into index.php as follows:
application
httpdocs
index.php
Our .htaccess file (in our public httpdocs folder) hold the following code:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
This works perfectly. However, for security purposes, I know want to move index.php to another sub-folder, so everything must be sent to my subfolder/index.php
httpdocs
subfolder
index.php
We tried the above and it worked successfully for all requests except the home page. It was done as follows:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ subfolder/index.php [NC,L]
My home page is not loading, it's having a limitless redirect problem.
Could anyone kindly please help me on this situation?
I believe it is because going to www.mydomain.com causes Apache to look for an "index.html" first. When this file is not found, it looks for an "index.php". Previously, my index.php was in the web root - so this line worked:
RewriteRule ^.*$ - [NC,L]
However now, there is no index.php there - it has moved to the subfolder. So this line should now work:
RewriteRule ^.*$ subfolder/index.php [NC,L]
However, the problem is that that file isn't loading. The unlimited redirect tells me that htaccess keeps redirecting to itself and doesn't actually reach the subfolder/index.php file
Can anyone advise what I should do to make this work, or to test further?
A background to this ticket: we have been advised by security experts that it would be best to "limit" which folders can run PHP. Since index.php is in the root, we would rather move this to a sub folder so that only that sub folder can run PHP, and not the root itself. There are more details here but if anyone has any advise/questions/opinions please shout.
Many thanks!
Since my customers hosting providers domain cpanel doesnt have the possibility to create subdomains, I've been trying to figure out how to mirror a subfolder from my htdocs to my root www folder within my .htaccess.
Root: /domains/{domain.com}/htdocs/www/
Sub: /domains/{domain.com}/htdocs/beta/
I need to keep the subdomain {beta.domain.com} intact to let everything work as planned. So when a customer visits {www.domain.com} or {beta.domain.com} he needs to see exact the same site with the domain kept intact.
DOCUMENT_ROOT is '/etc/apache2/htdocs'
Hope someone can help me out.
This this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beta\.domain\.com$ [NC]
RewriteRule ^/?$ /www/index.php [L]
At this moment I am helping him.
The hosting provider sucks but i can try to make it a little bit more clear.
The hosting provider build a difficult map structure but if got it, it is the following:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
If i want to add an subdomain they build the system as follow,
In the htdocs dir we should make a new map lets call it users.
We make a dir and the directory structure is as follow:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
users
Now if we go to: users.domainname.ext we will get directed to the directory users.
Note: This is the only way it's possible to make subdomains at the hosting provider.
Now what i did is add the following .htaccess file in the directory users.
RewriteEngine On
RewriteRule ^(.*)$ www.domainname.ext/ [L]
This will redirect to: www.domainname.ext
Now i added in the .htaccess of the www dir the follow:
# mod-rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^users\.domainname\.ext$ [NC]
RewriteRule ^(.*)$ /$1 [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
The problem is that the subdomain will redirect to the new domain, and what he want's is that url bar shows: users.domainname.ext instead of www.domainname.ext
Note: My .htaccess knowledge aint much but this is as far as i can get. So i bet i have things wrong :p in it but with this i came the farest haha.
Note 2: The part below is used for Zend Framework to work properly!
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have a website on Joomla 1.5 in my base dir - http://example.com - and another project written in Kohana 2.x - http://example.com/app.
The problem is that .htaccess in the subdirectory isn't working properly.
Question: How and which one .htaccess to configure? In subdirectory, my .htaccess file looks like this:
RewriteEngine On
RewriteBase /app/
RewriteRule ^(application|system) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
The project in subdir always tries to go to the controller named "app" when I type "http://example.com/app".
I have added the following:
RewriteRule ^(.*)$ index.php/$1 [PT,L]
RewriteRule ^$ index.php/$1 [PT,L]
And it is working perfectly!
The problem was with the hosting server. It did not handle the PT correctly and required to add above lines.
Everything worked fine:
https://example.com/app/auth
https://example.com/app/controller_name/param
However, the following did not work:
https://example.com/app
Seems like the index.php hasn't been added when nothing else were passed. Hence the line:
RewriteRule ^$ index.php/$1 [PT,L]
I'm currently developing a drupal based website but will have to keep a legacy system and many static pages/folders alive. It would be great if i could keep the old rubble in a separate folder than the new site. This would mean I've to merge both folders on the fly. I thought that this folder structure would be great.
/htdocs/legacy (symlink to old web root)
/htdocs/index.php
/htdocs/.htaccess
/htdocs/other drupal files and folders
/htdocs/...
This would mean that if i.e. mydomain.com/xyz.php is accessed the server should try to serve it in the following order.
if file or folder in /htdocs/ server this
if file or folder in /legacy/ serve this but do not rewrite the browsers location bar.
else rewrite pass it as querystring to the
I came up with the following rewrite rules. Which however don't work. I can either serve files in legacy or via drupal.
# 1. server from .htaccess folder
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [NC,L]
# 2. serve from legacy
RewriteCond /full-path-to-legacy-folder/%{REQUEST_URI} -f [OR]
RewriteCond /full-path-to-legacy-folder/%{REQUEST_URI} -d
RewriteRule ^(.*)$ /legacy/$1 [NC,L]
# 3. else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Has anyone of you suggestions?
Many thanks!
Since you're just rewriting the URL, and there are other operations that need to be done with the file (like mod_php), try changing your [L] options to [PT] to allow regular processing to continue on the request.