.htaccess web/ + secure directory 1and1 Webserver - apache

I am running symfony2.3. My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^/web/ - [L]
</IfModule>
I always have to enter www.example.com/web/en/. How can I get rid fo web/ ?
I also can get to files to www.example.com/composer.json. This should not happen. How can I secure it?
TIA!

Changing this line
RewriteRule ^/web/ - [L]
to
RewriteRule ^/ - [L]
should help with the first issue.
The second issue isn't possible if that file is used on a webpage. If a browser can access it then a user can.

This works.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>
But now I have www.example.com/de/ also www.example.com/web/de/. Is there a way to have only the first was?

Related

Symfony .htaccess adding rule for app_MYNAME.php

i want to add another app_MYNAME.php in the web folder.
This file is nearly identical to the app.php.
The only difference is this entry:
$kernel = new AppKernel('MYKERNELNAME', false);
I want to load different configuration files with these method.
When i type in the browser:
domain.de/app_MYNAME.php/VALUE
all is fine.
Now i want to hide the app_MYNAME.php. The Result should look like:
domain.de/VALUE
The second step is the redirecting. When someone type in the browser:
domain.de/MYNAME/VALUE
it should be redirected to:
domain.de/app_MYNAME.php/VALUE
I only get a 404 or a misconfigured message.
At the end i need 3 app_MYNAME.php files (app_MYNAME1.php, app_MYNAME2.php, app_MYNAME3.php).
I hope someone could explain me, what to put in the .htaccess file.
Here is my .htaccess file:
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Try with a configuration that looks like this in your .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
# ... Your other stuff
# RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_MYNAME.php [QSA,L]
</IfModule>
Also, make sure that your nginx/apache host file is pointing to the web directory of your Symfony project.
Try this :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_MYNAME.php [QSA,L]
Maybe all app.php could convert to app_MYNAME.php in your htaccess

htaccess and CakePHP3 routing (multiple "sites" same server)

Okay so I need just a little bit of help, I think i almost have my routing clean but am running into one small issue.
I am trying to setup one server to handle multiple different static sites as well as a cakephp 3 installation.
The root .htaccess has the following
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.domain\.com(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule ^(.*) /%2/$1 [E=SUBDOMAIN:%2,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
This works great for routing subdomains to their proper folder
static.domain.com properly goes to /static/index.php
the problem comes when i try to access my cake installation
cake.domain.com ends up routing to cake.domain.com/cake/$1
I really need it to route to cake.domain.com/$1
/cake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/cake/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(webroot/)?(img|css|js)/(.*)$
RewriteRule ^ index.php [L]
</IfModule>
I will be eternally grateful for any help, i have exhausted google searching and banging my head on the wall.
I am completely open to easier ideas as well

.htacces redirect all traffic to index.php and request for .js to another file

Hi Im Not very comfortable writing htaccess rules, my goal is
Redirect all traffic to index.php
Redirect all request to script.min.js to script.php
ultimately scripts.min.js does not exist rather the script.php will have set headers and include all needed JS files to create one master file. Also the status code should be 200.
Thank you in advance
I haven't tested this, but it'd probably look something like:
RewriteEngine On
RewriteRule ^script.min.js$ script.php [L]
RewriteCond %{REQUEST_URI} !/index.php$ [NC]
RewriteRule (.*) /index.php [L]
I was able to solve the problem by taking wordpress .htaccess and prepending the file match section
<IfModule mod_rewrite.c>
RewriteEngine On
<FilesMatch "\.(js)$">
RewriteRule . /scripts.php [L]
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Folder control with .htaccess

I have a directory /public_html/myfolder/ and I want my domain www.example.com to point to /public_html/myfolder/ as my root folder.
I figured that out, but problem is, my images are not showing.
Here's my .htaccess file:
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .* https://www.example.com/$1 [L,R=301]
RewriteRule ^$ myfolder/index.php [L]
# Require SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST} [L]
# Rewrite rules
<IfModule mod_rewrite.c>
#RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ myfolder/index.php?q=$1 [L,QSA]
</IfModule>
The issue may be that you have relative paths specified for your images on pages and after the URL is rewritten the links get broken. To fix this cosider using root-relative paths for the resources.
You will need to make sure the images are ignored by using RewriteCond's.
Try something like
RewriteCond %{REQUEST_FILENAME} !\.(jpg|png|gif)$
(not sure if the . should be escaped, but i think it should be)
You can also try adding
RewriteLog
RewriteLogLevel 3 (or maybe greater)
I'm not sure if this works if it is inserted into a .htaccess, it might be that it has to be in the server conf, but it is worth a try. It is easier to debug rewrite if you have the log.

Wordpress .htaccess errors

Thanks in advance to all you .htaccess guru's out there. I'm having an issue that's been bothering me for some time. I have wordpress nested inside my own site folder structure. To the user, everything is cool. But when i go to www.domain.com/blog/wp-admin, my credentials will not log in. It just keeps looping me around to the same page. If I go to www.domain.com/blog/wp-login.php directly it works. I wonder if anyone knows why this is.
The blog is located at /fe/blog/.
The .htaccess in / is:
Options +FollowSymlinks -Indexes
RewriteEngine on
RewriteRule ^(files)/?(.*) /files/$2 [NC,L]
RewriteRule ^(.*) /fe/$1 [NC]
The .htaccess in /fe is:
Options +FollowSymlinks -Indexes
RewriteEngine on
And Finally the .htaccess in the /fe/blog/ is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Any help would be greatly appreciated!
Try this in your /.htaccess file:
RewriteEngine on
RewriteRule !^(files|fe)/ fe%{REQUEST_URI} [NC]
And this in your /fe/blog/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
i wonder if this line is not the culprit:
RewriteRule ^(files)/?(.*) /files/$2 [NC,L]
could you try:
RewriteRule ^files/?(.*) /files/$1 [NC,L]
If not, you might also add the flag [QSA] (Query String Append)
RewriteRule ^files/?(.*) /files/$1 [NC,L, QSA]