Symfony .htaccess - .htaccess

I configured a test folder for websites in hostgator, so far I have no problems in some flatform like wordpress,magento,joomla, I did not even change any seetings in .htaccess to make it run. Recently, I am working on a symfony2 project and upload my test application in the test folder I created. This is how I create a test folder
mywebsite.com/tests/wordpress_site(no problem)
mywebsite.com/tests/joomla_site(no problem)
mywebsite.com/tests/symfony2_site(403 forbidden error)
In my WAMP, I can accessed my symfony project
localhost/symfony_site/web/
I did not touch the .htaccess since this is just a test site in local machine.
How would you configure a symfony2 project in this setup?
mywebsite.com/tests/symfony_site

It is almost impossible to create clean Urls when installing symfony in subfolder...
With Apache, the better solution is to use a VirtualHost which have tests/symfony_site/web as DocumentRoot, and to use the built-in .htaccess file (which uses url rewriting module, or if it not available, uses a 302 redirection to app.php/)
But If you can't add a virtualHost to your server, it is hard...
An other way is to add a .htaccess at tests/symfony_site and put DirectoryIndex: web/app.php
(https://httpd.apache.org/docs/current/mod/mod_dir.html)
So you can have clean URLs... but be careful with this solution: the urls parsed by the router are relative to your site root (and not to symfony root...) so the router might be lost... (e.g if you have a root named /test you should rename it /tests/symfony_site/test... And it is the same for assets, you have to add the site directory, otherwise they will return a 404 error...
In my case, I just use existing .htaccess in web folder (or I create a new one with a DirectoryIndex Instead), so my app work with URLs like mywebsite.com/tests/symfony_site/web/
I hope this helped,
Vincent

You can try typing the following code into the .htaccess file to the symfony root folder
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(img|files|images|favicon.ico|css|js|robots\.txt)
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{HTTP_HOST} host.com
RewriteCond %{REQUEST_URI} !web/
RewriteRule ^(.*)$ web/$1 [L]

Related

redirect /subdirectory to /symlink/subdirectory where /symlink points to /

i'm working on a drupal7 multisite setup based on subdirectories where example.com is used for the main website and example.com/subsite is another standalone drupal install. subsite is a symlink located in the root directory and also pointing to the root directory to give the subsite access to drupal core files.
now i have to make static content available via example.com/subsite/static, so i created a directory static in the root directory. that all works fine.
the problem is, that example.com/static is now also accessable and i want to prevent that.
i tried to redirect all requests to /static to /subsite/static resulting in inconsistent behaviour and redirect loops.
directory structure:
/
/{various drupal directories}
/subsite -> /
/static
rewrite rule:
RewriteRule ^/static/(.*)$ /subsite/static/$1 [R,L]
thx in advance
Is this what you want?
RewriteBase /
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
RewriteRule ^subsite/static/(.*)$ /static/$1 [L]
In the first line we redirect all call to /static/ to /subsite/static/.
In the second line we rewrite all call to /subsite/static/ to /static.
If it doesn't work please post your whole .htaccess file.
i fixed the redirect loops by using a rewrite condition, should have thought of that before.
RewriteCond %{REQUEST_URI} !^/subsite/(.*)$
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
thx anyway #florian-lemaitre for trying to help me

cakephp htaccess for production install

So, I have cakephp installed in what I believed to be the appropriate way for production code with actual cake files above the public_html folder. The app folder is removed from the cake folder and placed at the same level.
Loading the home page works fine with the databases and the debug working.
However, in trying to run some test files I get a 404. Obviously, I need some way to direct something like www.example.com/posts/index to the proper location. I am not sure as to why this is necessary since the index.php file tells cake where the app directory is located?
Also, if I need to use the .htaccess file, how do I point to the proper location and exactly what am I pointed at?
Update - I get the errors when I follow the blog tutorial and navigate to www.mywebsite.com/posts/index
If you have a production install the url example.com should point at app/webroot/, and the only .htaccess file you need is the default one from the webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Be sure to use the .htaccess file which corresponds to the exact version of CakePHP you are using as it has changed over the years.

.htaccess redirect dynamic domain to folder

For local development I've setup my router to redirect all requests to *.lan to my local xampp server. Now I have to setup virtual hosts for every domain I want to use. This works, but I don't want to setup a new virtual host (pointing to the corresponding folder) for every project and restart apache.
Is it possible to create a .htaccess file to "catch" a domain, and rewrite it to the folder, so I can use the domain as the folder name? For example:
example1.lan loads the website located in /example1/
example2.lan loads the website located in /example2/
This tread ( Apache - Domain for localhost to access folders as http://folder.local ) does almost the same thing, but with a redirect. I don't want a redirect, I want rewrite.
Thanks in advance!
Try adding these rules to the htaccess file in your document root (the directory where the example1 and example2 directories are):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.lan$
RewriteCond %{REQUEST_URI} !^/%1/
RewriteRule ^(.*)$ /%1/$1 [L]

How to setup .htaccess to rewrite to a different folder

I'm moving my site to a new host but I need to have my current server continue to handle requests (not all files can be moved to the new server).
So I added a parked domain to my old server (old.mydomain.com) and I want all requests to it to be written to the files from the old site.
My old site (mydomain.com) was hosted internally in a folder (/public_html/mydomain/) and I want all requests to old.mydomain.com to be rewritten to the same folder.
So if mydomain.com/blog was internally at /public_html/mydomain/blog, I now want old.mydomain.com/blog also to reach /public_html/mydomain/blog.
Here is the .htaccess that I'm trying to use:
RewriteCond %{HTTP_HOST} ^old\.mydomain\.com/*
RewriteRule ^(.*)$ mydomain/$1 [NC,L]
But for some reason as soon as I add the $1 in the rewrite rule I get an internal error.
Any ideas?
Configure this as a separate vhost called old.mydomain.com and ensure it comes before *.mydomain.com in your vhost definitions (i.e. higher in vhosts.conf). Give old.mydomain.com the same DocumentRoot as your previous domain had.
.htaccess is the most processor intensive way to serve a webpage, and should only be used there are no other options available.
Please try to fix your .htaccess config as follows:
RewriteCond %{HTTP_HOST} ^old\.mydomain\.com$
RewriteRule ^(.*)$ /public_html/mydomain/$1 [NC,L]

Creating SubDomains to Absolute Paths with .htaccess

Hey, My host is absolutely terrible. For some odd reason creating a subdomain in cPanel simply does not work, and their support lines are always busy. I thought I could get around this by using .htaccess. I'm sure it's not that hard, but I'm kind of new to mod_rewrite and have had little success searching in the last 5 hours. Heres the situation:
/home/user/public_html automatically redirects to http://www.example.com
Since I'm using a CMS in public_html it has already added the rule in .htaccess to redirect anything unfamiliar after example.com/ to a 'Page Not Found'
/home/user/subdomain needs to redirect to http://subdomain.example.com
How should I go about creating a subdomain redirection to an absolute path? Or How can I add an exception in my .htaccess
I doubt you'll be able to get your subdomain to function outside of your public_html folder (although I'm no server admin). Typically that requires DNS modifications or tweaking the server's configuration. Have you tried making a sub-directory and rewriting calls to the subdomain? For example this placed in the .htaccess within your public_html directory:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule (.*) /subdomain/$1 [L]
I'm not sure if that would work (never needed to test it myself), but it's more likely to function than trying to target files that live outside the directory specified by the webhost as the location of your domain's files.
Good luck!
Try this rule:
RewriteCond %{REQUEST_URI} !^/home/user/
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ /home/user/%1%{REQUEST_URI} [L]
But your webserver already needs to be configured so that every request of foobar.example.com gets redirected to this specific virtual host.

Resources