I have a symfony backend installed on my server and in the symfony/web folder I have created a new folder "app" and there is an index.html. If I call https://example.com/app/ I'm getting 404 and with https://example.com/app/index.html it is working. I have tried to change the DirectoryIndex in the symfony .htaccess from this:
DirectoryIndex app.php
To this:
DirectoryIndex app.php index.html
But it is still not working. How can I do it that if I call example.com/app/ the index.html will be opened (just for that folder to not destroy the symfony settings)?
You can use this line at top of your app/.htaccess:
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
# remaining rules go below this
Easiest way to do it:
# end of routing.yml
redirect_to_index:
path: /app/?
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app/index.html
permanent: true
But it will be /app/index.html, not just /app/.
Related
I want to redirect every requests to my public/index.php file. i've tried
RewriteEngine On
RewriteRule ^(.*)$ public/index.php?url=$1
code that seems fine but its not working. my goal is change url form http://example.com/?url=user/profile/2 to http://example.com/user/profile/2.
my directory structure is
root
public
index.php
vendor
.htaccess
composer.json
To handle URLs like: http://example.com/user/profile/2 please try following Rules sets in your .htaccess file. Place your htaccess rules file into root directory. Please make sure to clear your browser cache before testing your URLs.
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
OR try following rules, please make sure either try above OR following rules at a time only.
Above will work for non-existing pages, to make it for any url(like you mentioned in your question) try:
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !index\.php [NC]
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
heres the solution:
uncoment (remove # ) mod_rewrite.so module in httpd.conf file in apache2 (in my case c:\Apache24\conf\httpd.conf) file. also change AllowOverride none to AllowOverride All in that file under DocumentRoot "${SRVROOT}/htdocs" section.
and this is .htaccess content
RewriteEngine on
RewriteRule ^(.*)$ public/index.php?url=$1 [QSA,L]
RewriteRule ^()$ public/index.php?url=$1 [QSA,L]
however if you need to get static files in your static directory add a new .htaccess file inside static directory with RewriteEngine off content
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
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.
I've been working on this for quite a while to no avail.. I've got symfony installed on a shared web-host where I have zero access to change the DocumentRoot to the web/ folder so that is not an option to me...
I've written my htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^$ web/app.php [QSA]
RewriteRule ^(.*)$ web/app.php/$1 [QSA, L]
I have also tried this with RewriteBase web/ and RewriteBase /web/ to no avail.
With this, symfony is working.. I can login, I can do all of that... Only problem is, none of the assets are displaying... Chrome Developer Tools, is telling me it's finding a 404 which is right because it's not reading the /web/ folder as the DocumentRoot..
So, how to fix this issue without re-writing files, or anything.. There's got to be a way to do this with .htaccess only...
One way would be setting assets_base_urls in app/config.yml e.g
framework:
#..
templating:
engines: ['twig']
assets_base_urls: http://your.site.com/web/
Or, you can put a .htaccess file in your DocumentRoot folder and rewrite everything that comes in there to your /web folder accordingly:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>
With that you get clean URL's (omitting "web" or "app.php") and there is no need to use the assets_base_urls stuff in your config.
Basically all I want to do is this:
I have a URL to a PDF files on the server in this location:
http://chudz.co.uk/philaletheians.co.uk/Study%20notes/Atlantean%20Realities/Atlantis'%20study%20-%20Appendices%20and%20Notes.pdf
Now I want to remove this section of the URL:
/Study%20notes/Atlantean%20Realities/
This is what I have done in my htaccess file and it does not work:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/ /Study%20notes/Atlantean%20Realities/
I am new to this! as you can probably see above :) I have to keep the directory layout on the server as it is so my only option is to use mod_rewrite maybe?
Try adding the following to your .htaccess file in the root folder of your domain
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#if request does not already start with /Study notes/Atlantean Realities/
RewriteCond %{REQUEST_URI} !^/Study\ notes/Atlantean\ Realities/ [NC]
#rewrite it to the /Study%20notes/Atlantean%20Realities/ directory
RewriteRule (.*) /Study\ notes/Atlantean\ Realities/$1 [L]