The Zend project creates URLs like:
http://localhost/zftest/public/index/add
How can I have a URL like
http://localhost/zftest/add.php
Thanks.
First off, you seem to be after getting rid of the "public" part. There are two ways to it.
First, the .htaccess. In the project's root directory, create two files: index.php and .htaccess, with the following contents:
.htaccess:
RewriteEngine On
RewriteRule .* index.php
index.php:
<?php
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
And there you have it, no "public" in the URL.
The other way to achieve it is by setting up a domain. You'll need to modify two files: hosts and httpd-vhosts.conf. The hosts file is located at /etc/hosts under Linux or in C:\Windows\System32\drivers\etc\hosts under Windows. Both need root level access. Just add the line
127.0.0.1 zftest.local
Then find your vhosts file. I'm using XAMPP, so here are the paths to it for XAMPP: C:\xampp\apache\conf\extra\httpd-vhosts.conf under Windows, /opt/lampp/etc/extra/httpd-vhosts.conf. Just add something like this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/zftest/public
ServerName zftest.local
ServerAlias zftest.local
SetEnv APPLICATION_ENV development
SetEnv APPLICATION_DOMAIN zftest.local
</VirtualHost>
Now, when you go to zftest.local (choose any name you wish, of course), you'll see your front page, no "public" part in the URL.
As for the other part of the question, you need a custom router. Setting up a router is really easy and you can find lots of information about on the internet. Some prefer to do it in the bootstrap, but I believe the easiest way is to do it in the application.ini file. Here's a sample router:
resources.router.routes.getbyroute.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.getbyroute.route = "(.+)\.php"
resources.router.routes.getbyroute.defaults.controller = index
resources.router.routes.getbyroute.defaults.action = index
resources.router.routes.getbyroute.map.1 = action
resources.router.routes.getbyroute.reverse = "%s.php"
This should take care of your route (in theory, I haven't tested it for correctness, hehe). Investigate routers though, as you'll probably want something more generic than this (this one won't handle other controllers than index).
I hope this helps.
I don't see the problem with the default Zend routes as that style of URL mapping is considered a good practice (SEO friendly, clear mapping from URLs to modules, controllers and actions), but if you want to change the routing you should read up on the Zend Controller Router Documentation. Then your mapping might e.g. look like this:
<?php
$router = $frontController->getRouter();
$router->addRoute(
'add',
new Zend_Controller_Router_Route('add.php', array('controller' => 'index', 'action' => 'add'))
);
?>
This is normally accomplished by using Virtual Host document root, or more commonly by dropping in an .htacess file to redirect all requests to your /public/index.php.
See http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter for more details.
Related
How to change the Document Root for a specific domain/subdomain inside ISPConfig 3.
I need to point my subdomain to a different directory than the standard client3 web6 roots.
And in "ISPConfig 3" this field isn't editable, neither during creation nor afterwards.
The solution was pretty simple, All I had to do is, once the domain was created, I had to navigate as below..
Select that domain > Options > Apache Directives
And paste the following line where the root of the domain/subdomain would be adjusted accordingly. I wanted to point the domain to rainloop installation which was outside the Default Web Root directory /var/www/html.
DocumentRoot "/var/www/rainloop/"
Have written this Q/A as a documentation as in-spite of it being so simple, this solution isn't documented anywhere.
Hey yeah you can put this as directive snippsel:
DocumentRoot {DOCROOT_CLIENT}/YOURNEWFOLDER
in complete that shows something like this in your /etc/apache2/sites-available/ in the lower, isp config put this in:
DocumentRoot /var/www/clients/client10/web72/web/YOURNEWFOLDER
I am somewhat new to Laravel, and recently I got a setup at work to function exactly as I wanted. I have a single installation of Laravel with a subdirectory of apps that all use that same backend as a RESTful master.
The issue I'm having is that when I'm home, I've cloned this repo and changed the db settings to match my localhost at home (instead of at work). However, each time I try to load a rout for a resource I get 404'd!
Here's some code.
app/routes.php:
Route::get('/', function()
{
return 'fgh';
});
Route::any('config', function() {
return 'GET config';
});
//Main Rest Controller
Route::resource('main', 'MainController');
// Route::resource('config', 'ConfigController');
Route::resource('data', 'DataController');
The folder structure is:
|-- appREST (where Laravel is)
|-- shared
|-- apps (where the apps are)
What I am trying to do (which I do at work) is simply make an AJAX call from an app in the apps/ directory, but to a relative path that is adjusted for where appREST is.
At work, I AJAX to '../../../appREST/public/config', or ../public/main or whatever. However, for some reason, this fails at home. The same tables exist in both databases at work, and both are up and functioning (no one else has issues on either). It seems almost as if some local Apache or other setting on just my machine is failing?
I can load the first route for REST (Route::get('/')) in the browser, and 'fgh' IS displayed. However, even after changing to GET config and a string any call either AJAX or browser to any route but '/' 404s.
Also, as a note, in the meantime the applications themselves work fine. If I load static/hard data instead of what I'm trying to load, there are zero problems. This appears to be isolated to my routing in Laravel/Apache.
EDIT
I forgot to include the HTACCESS file for the /appREST/public folder. Here it is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
NOTE
The setup is a git repo and I actually have this on two separate machines. On the original machine, where the repo starrted as a working directory, the above code works fine. It is only on my home, clonedTo machine that the routes fail.
Does anyone have any ideas or suggestions?
Thank you!
The only way I eventually fixed this was a clean reinstall of both XAMPP and Laravel.
Given that I could find the '/' route and the errors were 404s, I'm going to tentatively call this an Apache error.
So, for anyone else having this issue: I suggest you check your XAMPP/web server settings if your Laravel routes 404!
I want to set the Zend Framework to run on a sub directory. Is it possible?
Maybe you're looking for Virtual host with apache ? But I'm not sure about what you're talking
http://framework.zend.com/manual/en/learning.quickstart.create-project.html
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot /path/to/quickstart/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/quickstart/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You have to add a baseUrl to your controller preferably in your bootstrap before you add the router.
$controller = Zend_Controller_Front::getInstance();
$controller->setBaseUrl('/subDirectory');
Note that this will add the base to all paths you are creating with the framework, i.e. the router. Lets say you have a collective /css folder you have to add the path for that either manually to any script method or create a subDirectory/css for that files.
I have several small projects I want to host on single virtual host using Zend Framework. The structure is:
apps/
testapp1/
application/
index.php,
testapp2/
application/
index.php
Document root in virtual host looks like: DocumentRoot /var/www/apps/
I need univeral mod_rewrite rule which will transform URLs like /apps/testapp1/xxx into /apps/testapp1/index.php.
Any help will be greatly appreciated as I am trying to resolve that for several hours. Thank You.
If your DocumentRoot for website is /var/www/apps/, then I guess URLs would be http://www.example.com/testapp1/ajax instead of http://www.example.com/apps/testapp1/ajax. If so -- then you need to remove apps/ part from these rules.
These rules need to be placed in your .htaccess into website root folder.
If you already have some rules there then these new rules needs to be placed in correct place as order of rules matters.
You may need to add RewriteEngine On line there if you do not have such yet.
This rule will rewrite /apps/testapp1/ajax into /apps/testapp1/index.php, no other URLs will be affected:
RewriteRule ^apps/testapp1/ajax$ /apps/testapp1/index.php [NC,QSA,L]
This rule will rewrite ALL URLs that end with /ajax into /index.php (e.g. /apps/testapp1/ajax => /apps/testapp1/index.php as well as /apps/testapp2/ajax => /apps/testapp2/index.php):
RewriteRule ^(.+)/ajax$ /$1/index.php [NC,QSA,L]
UPDATE:
This "universal" rule will rewrite /apps/testapp1/xxx into /apps/testapp1/index.php as well as /apps/testapp2/something => /apps/testapp2/index.php:
RewriteRule ^(.+)/([^/\.]+)$ /$1/index.php [NC,QSA,L]
for some weird reason my CMS is logging out if the address bar does not have www before the full website name. for example, when we enter xyz.com, it takes me to the website but then it wont show as logged in and if i type in www.xyz.com it will find the cookie and show me logged in.
What i want to do is, when user types in xyz.com, i want it to directly (transparent to user) go to www.xyz.com. I want to add that www before xyz.com. I tried adding a .htaccess file in the directory where index.php is present and this is code in htaccess file.
DirectoryIndex index.php
Redirect xyz.com www.xyz.com/index.php
The .htaccess file is disappearing when i transfer it over ftp filezilla.
If you are willing to modify your index.php you could add the following logic to the top of the file:
/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
$redirect = $_SERVER['REQUEST_URI'];
header( 'Location: http://www.mysite.com'. $redirect ) ;
}
try this in the htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]
However, your problem sounds like cookie related. Probably the CMS is using a cookie to check the log in status, but the cookie domain param is 'www.xyz.com' instead of '.xyz.com'.
--- edit ---
improved a bit the final line of the code (it is tested and working), but as tcp said, mod_rewrite must be enabled. If you can't enable it, try the code that Lobsterm posted and if you can't do this either, you could try to change the cookie domain param from 'www.xyz.com' to '.xyz.com'
If you want to use rewrites, make sure mod_rewrite is being loaded in your Apache conf file and check that the AllowOverride parameter is either set to All or the just the directives you want to be allowed in .htaccess
Also as aletzo said, you probably want your cookie to cover your whole domain so change the cookie domain from www.example.com to example.com .
Then, it won't matter if user are accessing with a www prefix or within a subdomain.
EDIT: Glad you found the answer you were looking for, but if you need to make filezilla show you .htaccess in the future, Server -> Force showing hidden files