I want to install my ZF2 application on a VPS server without support for Virtual Host. I´m using a simple application based on ZendApplicationSkeleton.
I´m using the default .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
All solution I´ve found in SO does not work for me. They may fit ZF1, but not ZF2:
Link 1
Link 2
Link 3
Link 4
My application is in a folder named /var/www/html/testapp.
The main page is loaded once I typelocalhost/testapp/public on the browser. Also my module is loaded if I type localhost/testapp/module, but navigation does not work.
Ie: in the main page, I´ve created a button like:
Go To Module
But if I click on it I navigate to localhost/login/index showing Not Found, not to the correct module/index.phtml page.
Help appreciated with that.
Your problem has nothing to do with server configuration. Since your app is in a sub-folder, the link is wrong. It would need to be something like
Go To Module
for it to work. However, public/ should never appear in you URLs. With things setup this way you are allowing users to view files outside your app's web root, which is a potential security risk (and results in ugly URLs).
The solution to this is to setup a separate vhost for your ZF2 app, which has a DOCUMENT ROOT pointing at the app's public folder. If you are having problems with this, post that as your question; or if you can explain why this isn't possible perhaps we can advise further.
Related
Issue half resolved...
Full resolution by me alone is probably not possible but I think I know what needs to be done.
Partially resolved part
After adding a new site in WordPress Admin and adding that site url to the cPanel "subdomains"; I:
Could ping subsite.domainName.xyz
Could not access the WP dashboard of subSite. Received 404 error.
Could not view the site (neither by clicking "Visit Site" nor typing url into a browser). Received a 403 Forbidden error.
After a lot of troubleshooting, a stumbled upon an article discussing how to disable indexing in cPanel. Luckily, for unknown reasons, I read the short article in its entirety and knew this was a golden ticket!
Spot checked many directories and sub-dirs to confirm yup! every directory made by initial default setup (GoDaddy/cPanel) had an index.php file in it.
None of the directories created (indirectly) by me had an index.php file (created via cPanel subdomain tool and WP Admin console).
I grabbed the index.php from my wp root :public_html (dir) and slapped that bad boy into my subsite.domainName.xyz sites folder and viola! I now receive a 500 err message
Hot dog we cookin now!
still can't view/"visit" the site [500 error message]
still can't access the WP Dashboard (admin console thingy). [was 404 error, now 500 error]
I looked at 4-5 other index.php files. A lot read "silence is golden" but others. Well, the other ones are incredibly extensive/long and intimidating.
Here is roughly what needs to happen.
Every directory (for subdomain site "subsite") needs to get a index.php file added (or simply turn off indexing for that entire subdirectory/subsite folder).
Some of those index.php files need to be extensive.
The dashboard, wordpress, and all content in the core/root WP install need to be point to or referenced by the index.php file so those files can be loaded there by displaying the Dashboard/webpages.
Completely or nearly copying all the root WP install files over to "subsite" directory would be the same as "install package on your new site" NO! Not doin it!
I simply need to figure out: how/what do I write/configure the index.php file to simply point upward so that everything that happens at domainName.xyz is replicated in subsite.domainName.xyz.
I am so close, if you have any information, please lay it on me!
None of the directories created (indirectly) by me had an index.php
file (created via cPanel subdomain tool and WP Admin console).
I grabbed the index.php from my wp root :public_html (dir) and slapped
that bad boy into my subsite.domainName.xyz sites folder and viola! I
now receive a 500 err message
You shouldn't need to be copying your index.php file to the subdirectories if hoping to connect them as part of a multi-site network AFAIK. While you could map each domain (which it sounds like you're doing) or create path-based on-demand sites, it's suggested that you make the changes directly in the network settings in your Super Admin panel and otherwise use of a plugin would surely ease your troubles.
However if you are to continue down this route, what you're looking to modify I don't believe are the index.php but the .htaccess files.
To be sure, check that you wp-config.php file has been set appropriately for sub-domain sites.
define( 'SUBDOMAIN_INSTALL', true );
Then, how you modify the .htaccess files will vary but one example from the examples given here would look like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
Then for the subdomains:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ wp/$1 [L]
RewriteRule . index.php [L]
# END WordPress
In doing this, it should address your need to have
all content in the core/root WP install need to be point to or
referenced by the index.php file so those files can be loaded there by
displaying the Dashboard/webpages.
Just for reference:
htaccess for subdirectories - overview of other uses of the .htaccess file As a side note, a .htaccess file is a granular configuration file for the Apache web server software, used to set or alter the server’s configuration settings for the directory in which it is present, and/or its child directories. It should go without saying that it is a hidden file in Unix/Linux and viewing of hidden files need to be enabled if using the File Manager in Cpanel or otherwise the -a option set when using ls -a
Changing File Permissions - It may be a matter of file permissions if the files were not made through Wordpress Network settings and would explain why you're getting a forbidden error.
How can I remove 'web/app_dev.php/' from my url when I want my symfony website to go live?
This is the default url during development,
http://{localhost}/my-symfony-2/web/app_dev.php/hello/World
So when I go live, I would like to be able to use this url to access my symfony website,
http://my-symfony-2.com/hello/World
Any ideas?
To hide app.php you need to:
having access at least to the web root of your site. Usually on the control panel of your web hosting space you can find from which you can upload your files (or if you have the access credentials you can install and use a Free FTP client like Filezilla).
checking if you have the mod_rewrite module installed and enabled in Apache looking the phpinfo() under "apache2handler" ---> "Loaded Modules" directory (you should have that possibility directly through the control panel).
After these checks you have to:
NOTE: Symfony2 already comes with an .htaccess file stored in the default web directory but if you don't know what are you doing it's better to replace the directives containet within the "IfModule mod_rewrite.c" with those shown below.
Use the native Symfony2 .htaccess or create a new one file with the .htaccess extension and copy/paste inside these directives to hide app.php in production (not on localhost):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteRule .? - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ app.php [QSA,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
# and from the symfony's original
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
To apply the modifications you need to restart Apache (also this is usually did on the control panel of your web space).
Googling a bit you can find tons of examples and tutorials but to start to learn take a look at this simple .htaccess guide with many useful infos and examples and the Official URL Rewriting Guide (Apache2.4). If you encounter some problem update your post adding all related infos otherwise you can make another question here on SO.
If you have access to the deployment server, from terminal you can use:
php app/console cache:clear --env=prod and this will clear the prod cache and you will be able to use the standard route.
But if you are deploying the application on hosting where you haven't access to terminal, need to find the app/cache/* and app/logs/* and remove their content and after add the proper rights (766|777) for the folders.
I have two problems with symfony. First one is, if I have two bundles created, only the first created bundle is shown when I go to localhost/symfony/web/app_dev.php/ As of now, I have the two bundles in my src/ both bundles are registered in the kernel, routes added and everything. But, I can only see the first created bundle, I don't know what to do, to see the second bundle in action.
Second problem is that, when I want to upload my finished symfony project, I can't see know how. Like, do I tell .htaccess to treat the app_dev.php files as index files, and to hide the folder name symfony from the URL, so that the mysite.com/symfony/web/app_dev.php to show as mysite.com/index.php because, I don't really get it.
Any help is much appreciated.
To "see second bundle in action", point your browser to some route of such bundle.
To be sure its routes have been registered, run:
$ php app/console router:debug
and see if they appear in the list.
Regarding deploying, you should read this topic.
Keep in mind that app_dev.php is meant for development environment, and should not be used for production; included .htaccess already routes all requests to app.php.
In order to make http://www.mysite.com/ your entry point, you should /yourproject/web be your webroot, or better use a symlink.
As the .htaccess part you way copy this into the .htaccess and put it in the root folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# DEV ENVIRONMENT #
RewriteRule ^$ symfony/web/app_dev.php [QSA]
RewriteRule ^(.*)$ symfony/web/app_dev.php/$1 [QSA,L]
# PROD ENVIRONMENT #
RewriteRule ^$ symfony/web/app.php [QSA]
RewriteRule ^(.*)$ symfony/web/app.php/$1 [QSA,L]
</IfModule>
I'm trying to set up a Drupal installation to be able to have clean urls. I have searched for the .htaccess-file in the root-folder, but haven't found it. In the phpinfo-file I created, I see under Loaded Modules mod_rewrite, so it is enabled on the server.
I created a .htaccess-file which contained a simple
RewriteEngine On
But when I ran the test under Configuration -> Search and metadata -> Clean URLs, it still failed. I then uploaded a .htaccess-file a friend sent me from a Drupal installation, but the test still failed.
What now?
The .htaccess for Drupal is a lot more complicated than a single line, I suggest you download a fresh copy of Drupal and take the .htaccess file out of the root folder and use that. If you can't find it I suggest turning on hidden files, there are different ways of doing this depending on your OS.
For a quick fix sake, adding these lines should sort your issue:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
I've searched and found a lot of questions on this site and elsewhere that are very similar, but I've tried implementing and modifying all the suggestions I've found and none of it works. I realize this is a very basic question an I am extremely frustrated because nothing I'm trying is working.
With that having been said... I am trying to organize my content pages within kurtiskronk.com/pages/... (e.g. kurtiskronk.com/pages/about.php)
What I want to do is make it so that I can simply link to kurtiskronk.com/about ... So how do I go about stripping "pages/" and ".php"? I don't have a ton of content pages, so it's not a big deal if I have to specify for each page, though something dynamic would be handy.
NOTES: I am using Rackspace Cloud hosting, and WordPress is installed in /blog. My phpinfo() can be seen at http://kurtiskronk.com/pages/phpinfo.php
This is my existing .htaccess file (in the root)
php_value register_globals "on"
Options +FollowSymLinks
RewriteEngine On
#301 redirect to domain without 'www.'
RewriteCond %{HTTP_HOST} ^www\.kurtiskronk\.com$ [NC]
RewriteRule ^(.*)$ http://kurtiskronk.com/$1 [R=301,NC]
RewriteBase /
RewriteCond %{ENV:PHP_DOCUMENT_ROOT}/pages/$1 -f
RewriteRule ^(.*)$ pages/$1 [L]
RewriteCond %{ENV:PHP_DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^(.*)$ pages/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/ blog/index.php [L]
# PHP - MAIL
php_value mail.force_extra_parameters -kurtis#kurtiskronk.com
I tested and the rewrite works with the line below (/about as URL brings up file /pages/about.php), but then the homepage gives a 500 Internal Server Error:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /pages/$1.php [L]
So I'm still sort of in the same boat as before, and as a follow-up, possibly more difficult question, if you go to http://kurtiskronk.com/weddings I am using SlideShowPro (flash) w/ SSP Director (self-hosted) as the back-end for it. When it pulls up a new image, it adds the following after /weddings ... "#id=album-152&num=content-9698"
There are four sections of the portfolio
# Homepage (kurtiskronk.com) id=album-148 ($id is constant for this section)
# Weddings (/weddings) id=album-152 ($id is constant for this section)
# Portraits (/portraits) id=album-151 ($id is constant for this section)
# Commercial (/commercial) id=album-150 ($id is constant for this section)
Assuming we get kurtiskronk.com/weddings to rewrite successfully without breaking anything, how would we make the total URL something cleaner kurtiskronk.com/weddings/9698 since the $num is the only thing that will change within a given section?
Kurtis, thanks for the extra information. It's a lot easier to give a specific answer to this.
My first comment is that you need to separate out in your thinking URI space -- that is what URIs you want your users to type into their browser -- and filesystem space -- what physical files you want to map to. Some of your mappings are URI->URI and some are URI->FS
For example you want to issue a permanent redirect of www.kurtiskronk.com/* to kurtiskronk.com/*. Assuming that you only server the base and www subdomains from this tree, then this cond/rule pair should come first, so that you can assume that all other rules only refer to kurtiskronk.com.
Next, you need to review the RewiteBase documentation. .htaccess files are processed in what Apache calls a Per-Directory context and this directive tells the rewrite engine what to assume as the URI base which got to this directory and .htaccess file. From what I gather, your blog is installed in docroot/blog (in the filesystem, and that you want to get to directory by typing in http://kurtiskronk.com/blog/ but that this .htaccess file is for the root folder -- that is the base should be (this goes before the www mapping rule)
DirectorySlash On
DirectoryIndex index.php
RewriteBase /
#301 redirect to domain without 'www.'
RewriteCond %{HTTP_HOST} ^www\.kurtiskronk\.com$ [NC]
RewriteRule ^(.*)$ http://kurtiskronk.com/$1 [R=301,NC]
You can add some field dumps look for REDIRECT_* in the Server or Environment table in the phpinfo O/P to see if these are sensible. For example:
RewriteWrite ^(.*)$ - \
[E=TESTDR:%{DOCUMENT_ROOT}/pages/$1.php,E=TESTPDR:%{DOCUMENT_ROOT}/pages/$1.php]
Your next rule is that if the file exists in the subdirectory pages then use it:
RewriteCond %{DOCUMENT_ROOT}/pages/$1 -f
RewriteRule ^(.*)$ pages/$1 [NS,L]
[Note that some shared service sites don't set up DOCUMENT_ROOT properly for the rewrite engine so you may need to run a variableinfo script (<?php phpinfo(INFO_ENVIRONMENT | INFO_VARIABLES); to see if it sets up alternatives. On your site you have to use %{ENV:PHP_DOCUMENT_ROOT} instead.]
Your next rule is that if the file exists, but with the extension .php in the subdirectory pages then use it:
RewriteCond %{DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^(.*)$ pages/$1.php [NS,L]
Now redirect any blog references to the blog subdirectory unless the URI maps to a real file (e.g. the blog stylesheets and your uploads.)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/ blog/index.php [L]
A complication here is that WP may be using a poorly documented Apache feature call Path Info that is a script can act as a pseudo directory so http://kurtiskronk.com/blog/tag/downtown/ is redirected to docroot/blog/index.php/tag/downtown/ which is then executed by `docroot/blog/index.php using /tag/downtown/ as the PATH_INFO. But this is one for Wordpress experts to comment on. If this last rule doesn't work then try:
RewriteRule ^blog/(.*) blog/index.php/$1 [L]
PS. I like your site. I wish I was that young again :(
Postscript
When you say "it doesn't work", what doesn't with this .htaccess?
http://kurtiskronk.com/phpinfo,
http://kurtiskronk.com/phpinfo.php,
http://kurtiskronk.comblog/tag/downtown/
It's just that these rules work for these tests (with domain swapped) on mine. (One way is to move or copy the above variableinfo.php to the various subdirectories. If necessary temporarily rename the index.php to index.php.keep, say, and copy the variableinfo.php to the index.php file. You can now enter the various URI test patterns and see what is happening. Look for the REDIRECT_* fields in the phpinfo output, and the SCRIPT_NAME will tell you which is being executed. You can add more {E=...] flags to examine the various pattern results. (Remember that these only get assigned if the rule is a match.
Lastly note the changes above especially the additional NS flags. For some reason mod_rewrite was going directly into a subquery which was resulting in redirect: being dumped into the file pattern. I've had a look at the Apache code and this is a internal botch to flag that further redirection needs to take place (which then replaces this or backs out). However this open bug indicates that this backout can be missed in sub-queries and maybe that's what is happening here. Certainly adding the NS flas cured the problem on my test environment.
PS. Note the added explicit DirectoryIndex directive and also that whilst http://kurtiskronk.com will run the root index.php, the explicit /index.php version will run the one in pages, because that's what your rules say.
Here is a simple solution. You can use it apache conf file(s) or in .htaccess (easier to set up when you're trying).
mod_rewrite has to be enabled.
For example, use .htaccess in your DocumentRoot with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /pages/$1.php [L]
It will redirect /about to /pages/about.php, and any other page.
The "RewriteCond" part is to authorize access to an existing file (eg: if you had an "about" file at the root of your site, then it will be served, instead of redirecting to /pages/about.php).
Options +FollowSymLinks
RewriteEngine On
RewriteRule /([0-9]+)$ /pages/$1.php [L]
Put something like this in your .htaccess file. I guess that is what you want.
Juest a redirect from a simple url to a longer url.