htaccess symfony2 redirect to web directory - .htaccess

I've just published my symfony proyect, but the url is http://url.com/web/. I want to change my .htaccess to point to web directory. So, the url I want it to be like http://url.com/. I've tried to change my .htaccess but I have not been successful.

my project is in a shared host and i can't create a virtual host. I used this .htaccess file in symfony root and works.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/web/app_dev.php - [L]
RewriteRule ^/web/app.php - [L]
# Fix the bundles folder
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
# Fix the assets folder
RewriteRule ^assets/(.*)$ /web/assets/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>
https://undebugable.wordpress.com/2014/11/12/symfony2-htaccess-to-redirect-request-from-web-to/

Please read that page and look the Apache configurations.
http://symfony.com/doc/current/setup/web_server_configuration.html

Related

How to remove this part from URL using htaccess?

I have this URL:
http://www.register.abc.com/myapp/administrator/registration
Which is :
http://www.register.abc.com is my domain
myapp is my aplication folder in server
administrator/registration is my controller and function
What I'd like to do is to remove this part /myapp/administrator/registration from my URL. In default, when user only enter the http://www.register.abc.com/ it will be redirected to my home page. I'd like to set it so the user directly enter registration page not the home page. I have little to no knwledge about .htaccess. Any help is greatly appreciated.
Note: I am using wiredesignz codeigniter modular extensions hmvc
Edit:
my current .htaccess is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myapp
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
In your site root .htaccess (a level above myapp/ you may try this .htaccess code:
RewriteEngine On
RewriteRule ^$ myapp/administrator/registration [L,R=302]
If you want an internal rewrite (without changing URL) then try:
RewriteRule ^$ myapp/administrator/registration [L]

How do you redirect all request to public/ folder in laravel 5

I have a classic Larevel 5 project structure and I need to redirect all requests to public/.
I am on a classic hosting environment so public/ is a subfolder of my document root.
I shall imagine it can be done via .htaccess but I still need to figure out how. Anyone can help?
Thanks
There are two solutions:
1. Using .htaccess with mod_rewrite
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
2. You can add a index.php file containing the following code and put it under your root Laravel folder (public_html folder).
<?php
header('Location: public/');
You don't need to change anything in Laravel's default public/.htaccess file.
Just create a new .htaccess in the same level your public folder and add the following content to it:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
That simple!
This is an extract from another answer which may also help you.
--
Modify your public_html/.htaccess to redirect all requests to the public subfolder.
# public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect All Requests To The Subfolder
RewriteRule ^ /public
</IfModule>
Make sure you have the proper public_html/public/.htaccess (GitHub).
# public_html/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization}
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
If you use cPanel, then:
1.Go to folder:
/var/cpanel/userdata/my_domain
2.Edit the both domains:
my.domain and my.domain_SSL
Add to the documentroot section /public:
documentroot: /home/user/public_html/public
3.Rebuild Apache config:
/scripts/rebuildhttpdconf && service httpd restart
if you using apache , add .htaccess file to your root directory with this lines :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
and make sure your apache redirect and rewrite modules is working fine .
you can use vhost to redirect the all request to your public directory with set public as root of your project .
The ideal scenario is to have /home/user/public as a symlink from /home/user/laravel/public.

Symfony htaccess hiding app.php

The following .htaccess was able to allow my symfony project domain to be served without app.php in the URL, as intended. The only issue is that it is breaking all other (non-symfony related) urls and causing an internal server error.
Right now, after deleting the .htaccess file from the server, all my domains work but the project tied to symfony must be accessed using app.php in URL ?
Is it possible to modify the below .htaccess to rewrite the symfony url to not require app.php in the URL while still allowing for all other URLs, not tied to symfony, to be accessed successfully?
Not sure this is needed, but assume the domain tied to symfony is www.apples.com.
Thanks in advance!
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
Edit
I also tried the following:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
DirectoryIndex index.php
</IfModule>
Right after
RewriteCond %{REQUEST_FILENAME} !-f
add
RewriteCond %{REQUEST_FILENAME} !-d
and set DirectoryIndex to index.php
A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.
<Directory "/web/symfony-project">
FallbackResource /app.php
</Directory>

Exclude a root folder from CakePHP app

I am trying to exclude a first level directory from Cake (root folder app), as it should hold a different app.
/ holds the app
/development/ holds the tested version of the app
The directory structure:
Public folder
.htaccess [modified]
app
.htaccess [unmodified]
webroot
.htaccess [unmodified]
index.php [unmodified]
...
...
lib
Cake
...
development
app
webroot
index.php [dumps $_SERVER for test purposes]
So, my development structure still doesn't have an app inside (nor .htaccesses), just to test if my root .htaccess works.
This is my modification of the root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/development.*
RewriteRule (.*) - [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
What happens:
/development/ shows the apache index of development folder
/development/app/ shows the apache index of app folder
/development/app/webroot shows the root app (request is captured in spite of the development url match).
/development/app/webroot SHOULD show me my /development/app/webroot/index.php file, right?
What the hell am I missing here?
This turned out to be an oddball bug on my server.
The resulting .htaccess which works now is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/development(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/development(?:$|/)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
For reasons unknown to me, if I SSH'd to my user account and edited the .htaccess files through the command line, it wouldn't work!
When I uploaded the same files (via SFTP), it started working properly.
I am using cPanel (11.34.1) on CentOS (5.9).
Another example: if you wish to "ignore" multiple sub-folders on a CakePHP installation, you can use this pattern:
<IfModule mod_rewrite.c>
RewriteEngine on
# /development, /version1.5 and /version1.8 directories
# they all hold independent apps
# or completely non-cake-related content
RewriteCond %{REQUEST_URI} !^/(?:development|version1\.5|version1\.8)(?:$|/)
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/(?:development|version1\.5|version1\.8)(?:$|/.*)
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Note that both RewriteCond instructions are identical.

Redirect subdir with .htaccess

My first question here! :) Hello!
I have some trouble with .htaccess.
http://www.domain.com/subdir/?parameter=example works.
http://www.domain.com/subdir/example doesn't work.
When i try this:
RewriteBase /subdir
RewriteRule ^index.php - [L]
RewriteRule ^([^/]+)/?$ index.php?i=$1 [R,L]
i get an 404.shtml error like http:// www.domain.com/subdir/index.php?i=404.shtml
Also the wp-admin(http:// www.domain.com/wp-admin/) redirects to the subdir with 404.shtml. How do i get the url like http:// www.domain.com/subdir/example/
Can anyone help me?? Thnx in advanced!
Assuming this is a WordPress installation (based on the mention of 'wp-admin'), you want the following
Just use the WordPress standard, put this .htaccess into the root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]
</IfModule>
Go to Settings and change Site address (URL) under General Settings to http://www.domain.com/subdir/
Put the following index.php into the root folder
<?php
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./subdir/wp-blog-header.php');
?>
Go to Settings > Permalinks and change the permalink structure to whatever you need
p.s. to access wp-admin you need to navigate to http://www.domain.com/subdir/wp-admin/
more info here: http://codex.wordpress.org/Moving_WordPress#Giving_WordPress_its_Own_Directory_While_Leaving_the_WordPress_Index_File_in_the_Root_Directory

Resources