Zendframework project shows xyz.com/public/ so how to remove public - php

My zendFramework application on server shows
xyz.com/public/login
i want it like
xyz.com/login
how to achieve this ? is it possible to do with .htaccess file?

This is my answer from another question, but seems to fit in this question too. In the case you already have a .htaccess file inside public, use the htaccess solution from below.
The problem seems to be due to the root not being routed to /public.
The proper way: You need to setup a vhost and point the root to the public directory.
Another Way: You need to redirect every request inside public directory. The .htaccess for this file would be
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]

You have to create a virtual server Zend have a tutorial to do so.
If you are not able to create virtual server by any reason. You can put the public index.php file outside the public folder. If you choose this method you have to add extra security methods, choosing this method lead to direct access of files.
You can prevent those direct access by creating .htaccess in those directories with these lines-
<Files *>
Deny from all
</Files>

Related

Need help writing an htaccess, in cpanel hosting that helps me access my symfony 2 application without any /web or folder names in url

I have a c-panel shared hosting. Now, the docroot for the sitename.com resides at public_html folder. Say, I have a symfony application installed in the same. So, the web folder for my symfony application is at public_html/symfony/web/. If I want to try it, I should hit sitename.com/symfony/web/app_dev.php.
Here's the tricky part: I am trying to use htaccess somehow to get sitename.com/hi to invoke sitename.com/symfony/web/app_dev.php/hi internally. The constraints are, I cannot modify my httpd-vhosts.conf to update my hosting directory. It might not be a practical thought, still, would love to figure out this, just as some food for thoughts.
try this in your public_html
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
Edit .htaccess in public_html folder and add rewrite directives to pointing your request to wanted foder /symfony/web/ :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename.com$ [NC,OR]
RewriteCond %{REQUEST_URI} !symfony/web/
RewriteRule (.*) /symfony/web/$1 [L]
DirectoryIndex app.php
If you are using /symfony/web/app.php as front controller don't forget to add directive DirectoryIndex.

MVC public folder htaccess is not working

I recently moved my index.php (the file that handles routing) and CSS, JavaScript, and font assets to a public/ folder. I only want items in this public/ folder to be accessible for security purposes. I ran into this problem when I realized I could visit mysite.com/composer.lock and view the composer lock file with my old .htaccess and folder setup.
Here is what I want
If I visit mysite.com/car/create, I want it to actually point to mysite.com/public/index.php?path=car/create
If I link to an asset such as mysite.com/css/style.css, I want it to really point to mysite.com/public/css/style.css
Here is my folder structure
Here is my .htaccess which is not working at all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ public/index.php?path=$1 [L,QSA]
</IfModule>
How can I fix this? It just generates empty pages and I can still directly visit files in the root directory, etc.
Your existing directives specifically avoid rewriting requests for existing files, so it would still enable you to visit files in the root directory. It will also rewrite static resources to public/index.php?path=, which will presumably fail.
Try the following instead:
RewriteEngine On
# Stop processing if already in the /public directory
RewriteRule ^public/ - [L]
# Static resources if they exist
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
# Route all other requests
RewriteRule (.*) public/index.php?path=$1 [L,QSA]

How to access an ZF2 application without “public” in URL

I completed my project on ZF2, then uploaded it on shared hosting. I would like a folder for the zend app with all the files inside, and then in the document root I would like the files from the public folder to be visible, because I want my URIs to look like www.example.com (not www.example.com/public/).
What I have done in those cases with ZF1 app is to throw an app directory in the document root and with your server's .htaccess equivalent made it not serve files from there (Deny from all). Then stick your gateway script into the document root and update the paths found in there including APPLICATION_ROOT and the path to the autoloader.
Hope this helps.
You can move the files inside /public to your webroot. However, please be aware that config files below your webroot are a security risk.
This one work.
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]

Running a Zend Framework Project on a shared server

I'm trying to upload my ZF Project to shared hosting
On my XAMPP, ZF's index page is located (and I access my page) at http://localhost/ZFprojectname/public
On the shared hosting in the root directory I have installed Joomla.
I want to access my ZF in the manner of http://mywebsite.com/booking/
so in this case, when going to http://mywebsite.com/booking/ I should be accessing ZF's public folder (as far as I understand).
And, I'd like to put my ZFproject in public_html/somefolderName/
How would you do it?
Shared hosting do not support defining Document Root path so you can use .htaccess to forward the request to public folder instead.
Create a .htaccess file inside the booking directory with the following rule.
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]

URL Shortening in Apache 2

I have a site with homepage as /var/www/mysite/index.html
Now I want to direct www.mysite.com/x2312d to /var/www/mysite/app/pass.php?id=x2312d
How do I do this?
Where should I create .htaccess file and what should be the contents of it?
in your root /var/www
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ /app/pass.php?id=$1 [NC,L]
put the .htaccess file in /var/www/mysite/app/. I'm assuming your docroot is /var/www/mysite/
make sure apache 2 has the rewrite module enabled
.htaccess:
RewriteEngine On
#allows you to still access static items in this dir
RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g)$
#sent it all to pass script
RewriteRule (.*)$ pass.php [L]
I like this method, assuming pass is some sort of controller. My controller for a rest api parses the /x23123d manually from the $_SERVER global var, but you could use a different rewriterule to have it be in the $_GET/$_REQUEST['id'] global var.
something like this:
RewriteRule ^app/(.+)$ app/pass.php?id=$1 [PT,L,QSA]
Good References: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
edit: almost forgot, don't forget to handle trailing slashes too.

Categories