htaccess - Options FollowSymLinks or SymLinksIfOwnerMatch is off issue - apache

im using plesk for hosting my webpage. And evertime when im opening the root domain (e.G: "xxxxxx.xx"), my vServer is logging following error:
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/vhosts/xxxxxx.xx/httpdocs/index.pl
I do not have index.pl file in httpdocs.
And this error occurs not, when i call "xxxxxx.xx/index.php" or other pages.
My htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^products/(.*)/(.*)/$ products.php?id=$1&p=$2 [QSA,L]
RewriteRule ^static/(.*)/(.*)/$ static.php?id=$1 [QSA,L]
RewriteRule ^index\.php$ - [L]
Any ideas, how i can solve this problem?

I know this may not sound right but in your plesk domain settings make sure cgi support is checked but perl support is unchecked. I could not get my 403 forbidden errors to go away when using mod_rewrite rules even with a modified Apache conf file. Once I unchecked the perl option in the plesk config for the domain perl rewrites work.

Related

.htaccess eg.php?id=3 to eg/id/3

Problem:
I know there are alot of examples like the title on the web, but non of them work properly for me. How do I get my .htaccess to rewrite AND redirect ALL pages like /eg.php?id=3 to /eg/id/3 and /eg.php to /eg
My current .htaccess
ErrorDocument 404 /404.php
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
EDIT (WORKS)
RewriteEngine On
RewriteRule ^/?([^/]+)/id/([0-9]+)$ $1.php?id=$2 [L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /404.php
<Files .htaccess>
order allow,deny
deny from all
</Files>
Fixes StyleSheet errors:
<head><base href="http://website.com/"></head>
I'd say that should do what you ask for:
RewriteEngine on
RewriteRule ^/?eg/id/([0-9]+)$ eg.php?id=$1 [L,QSA]
RewriteRule ^/?eg/?$ eg.php [L,QSA]
Obviously the interpretation of .htaccess style files has to be enabled and the rewriting module has to be loaded for this to work.
This is a more general version as asked in the comments below:
RewriteEngine on
RewriteRule ^/?([^/]+)/id/([0-9]+)$ $1.php?id=$2 [L,QSA]
RewriteRule ^/?([^/]+)/?$ $1.php [L,QSA]
This further version should redirect requests still carrying a .php ending to their new versions:
RewriteEngine on
RewriteCond %{QUERY_STRING} (.*)(?:^|&)id=([^&]*)((?:&|$).*)
RewriteRule ^/?([^/]+)\.php$ $1/id/%2 [L,R=301,QSA]
RewriteRule ^/?([^/]+)\.php$ $1 [L,R=301,QSA]
RewriteRule ^/?([^/]+)/id/([0-9]+)$ $1.php?id=$2 [L,QSA]
RewriteRule ^/?([^/]+)/?$ $1.php [L,QSA]
And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using .htaccess style files. Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).

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

Ember/Ember-Cli Serving through Apache throws 404

I'm running into a problem when I try to serve my ember app through Apache. Because the location is set to "history" and not "hash", Apache is trying to load the magic ember routes which don't exist as files. myapp.com/login throws a 404 because there is no login.html.
I've done a bit of scouring and its surprising that there isn't much on this which leads me to believe that not many people deploy ember apps on apache.
So it's suggested I write Apache URL Rewrite rules, but the one's I have tried don't seem to be working.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.html [L]
and
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Don't work.
Does anyone have any idea of what to do other than go back to "hash"?
Regards, Clueless person.
You need to route everything to index except the files that exist:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html#$1 [L]
If you can back to hash, you can change the locationType setting it to "hash".
Check it out the next answer:
https://stackoverflow.com/a/28630973/4425050
I had the same problem and I fixed it with that.

RewriteRule isn't working

I'm trying to remove .php extension from .htaccess . I'm running Apache web server on Ubuntu . Have enabled mod_rewrite.c (module) and from virtual host configuration AllowOverride option as well
In .htaccess I've following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
</IfModule>
Which goes to 404 , but if just try to redirect from specific file to anywhere it is working , that's makes me think that I've problem with code written above , any suggestions ? thanks ...
Options +FollowSymLinks
RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Above code perfectly works for me. I am also using Apache web server on Ubuntu.

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.