Restler returning different formats depending on final slash - restler

I am using restler with mod_rewrite and making use of the "Accept" HTTP header to return the correct resource representation.
When making requests with the "Accept: application/json" in my production environment:
http://example.com/site/collection/1/ the response is correct and formatted as json.
http://example.com/site/collection/1 the response is correct but formatted as xml.
In my development environment both these requests return the same result formatted in json and that is the way I would like it to be.
In both environments I have the .htaccess file in place:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<ifModule mod_php5.c>
php_flag display_errors Off
</IfModule>

Related

htaccess header not applied on http file

I want to add HTTP response header using htaccess file, but it is not applied on the main file while all resources like css and img files gets that header. My htaccess file looks like this:
RewriteEngine On
Header always set test-header "value"
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://myurl.goes.here/$1 [R,L]
</IfModule>
I tried to move "Header set" line across different places in my file but that didn't help.
Most likely the issue was because of using php fastcgi like described here. I'm using managed service so unable to change configuration, but adding headers in PHP code by using header command worked fine.

How to rewrite URL to index.php in MVC-like approach

When rewriting the URLs for my MVC style application with RewriteRule(s) in my .htaccess file I am having a problem with the URL getting longer and longer.
There you can find a (not) working example: https://rossi.klingt.org/new/
I've tried several rewriting rules i found here like in this question
I'm running:
Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64
PHP Version 7.2.9-1
Can't get the exact Apache version
The code I'm using in my .htaccess file in the folder /new/ at the moment is this:
<IfModule mod_headers.c>
Header always append X-Frame-Options SAMEORIGIN
Header set X-XSS-Protection "1; mode=block"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /new
RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^.*) index.php [L]
</IfModule>
If you click a link, it will be added to the end of the URL. I expected it to behave differently. I did a similar thing on a pretty old system and it only kept the last folder and did not add them up.
What am I missing? Any help would be appreciated! Thank you all!!
OK, I just found out what went wrong.
I was looking for a solution in the wrong place.
By adding a tag to my section the browser now knows how to deal with the relative paths of my links and does not glue the new link on to the right end of the URL!
My current .htaccess code is the following
Options -MultiViews
Options -Indexes
<IfModule mod_headers.c>
Header always append X-Frame-Options SAMEORIGIN
Header set X-XSS-Protection "1; mode=block"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /new
RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,NC,QSA]
</IfModule>

Deploying Api Laravel and Front-end Vuejs

I'm trying to deploy my application on hostinger but I cannot. I've created an API with Laravel and the front-end with VueJS. Then, I have in my server folders:
public_html
index.html
static
api
public
.htaccess
Within my api folder, I have all laravel files to my API and in my .htaccess file in public folder I have this code:
DirectoryIndex public/index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L, R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>
For example, in my mydomain.com I get data from api.mydomain.com/api/some_url but I'm getting errors with cross-origin.
Can anybody help-me how to correctly set up my htaccess to comunicate my domain.com with my api.domain.com/api/some_url?

.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>

.htaccess DirectoryIndex not working

I have a website running on Linux/UNIX but I don’t know a darn thing about the .htaccess file and the syntax used in it..
If you go to http://pr.bananapages.net the system won’t produce any results.
But if you add the file name, it comes up. ex: http://pr.bananapages.net/index.html
NOTE: The URL points to a subfolder on the shared access hosting server but it doen't really matter because when you type in www.bananapages.net/pr/hamshack, (That's where the short cut DNS address points to), It still won't produce the index.html file without actually specifying it.
I have tried everything I could find about DirectoryIndex but I can’t get it to work without using the file name… (index.html)
This is my current .htccess file.
Options -MultiViews
DirectoryIndex system.php index.php
<IfModule mod_rewrite.c>
DirectoryIndex system.php index.php index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Google sitemap controller
RewriteRule ^sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^tmp/sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^index.html$ index.html [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)(\.xml|\.php([0-9]*)|\.tpl|\.phtml|\.ini|\.inc|/)$ system.php?_p=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ system.php?_p=$1 [QSA,L]
</IfModule>
# compresses text, html, javascript, css and xml
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
</IfModule>
NOTE: If I rename the .htaccess file, it will work without specifying the filename, (index.html) so. I am fairly certain there is something in this .htaccess file preventing this from working the desired way.
You can try this:
in all your
RewriteCond %{REQUEST_FILENAME} !-f
Double it as thus, to say to do rewrite only if lt's neither directory, nor file:
Edit
(Tested in Debian/Apache2).
Options -MultiViews
DirectoryIndex system.php index.php index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Google sitemap controller
RewriteRule ^sitemap.xml$ tmp/sitemap.xml [L]
#RewriteRule ^tmp/sitemap.xml$ tmp/sitemap.xml [L]
#RewriteRule ^index.html$ index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(\.xml|\.php([0-9]*)|\.tpl|\.phtml|\.ini|\.inc|/)$ system.php?_p=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ system.php?_p=$1 [QSA,L]
to see if it works better? Please notice some commented infinite loop rewriterule.
I had a similar situation on my vps
I wanted my default homepage to be login.php so if someone where to go to http://[ip]/[folder]/ it would just load the login.php file that I set in my .htaccess within the [folder]
so i set 'DirectoryIndex login.php' in .htaccess but
it would not work instead I would get a 403 when going to http://[ip]/[folder]/ as I didn't have any index.html or index.php
so...
I decided to check the apache config file httpd.conf and under DirectoryIndex I put 'login.php' as part of the list that was already there then restarted the httpd service and
it worked for me!
Here's the answer...
# Rules for subfolders
# for pr.bananapages.net
RewriteRule ^pr/(.*)$ pr/$1 [L]
# for jm.bananapages.net
RewriteRule ^jm/(.*)$ jm/$1 [L]
# and so on....
RewriteRule ^dr/(.*)$ dr/$1 [L]
RewriteRule ^usvi/(.*)$ usvi/$1 [L]
RewriteRule ^bvi/(.*)$ bvi/$1 [L]
RewriteRule ^kitts/(.*)$ kitts/$1 [L]
RewriteRule ^ar/(.*)$ ar/$1 [L]
RewriteRule ^tt/(.*)$ tt/$1 [L]
I don't know why that works but it does seem to work...
Dale