I am trying to convert this apache .htaccess rule to something nginx can use.
This .htaccess is a part of this tutorial to make a php REST api. ( http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-23/ )
The idea of this .htaccess file is to make a REST get/post request to "task_manager/v1/register/"
and it redirects you to "task_manager/v1/index.php"
.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
I've tried one idea from stackoverflow, one from winginx, and I tried writing one myself and they all sort of flop.
Nginx config:
something I tried and failed so I commented it out.
rewrite ^/task_manager/v1/(/)$ /task_manager/v1/index.php redirect;
something I saw in stackexchange and didn't help, so I commented it out
rewrite ^task_manager/api/v1/([^/]+)/([^/]+)/?$ task_manager/api/v1/index.php?class=$1&method=$2? last;
was recommended to use winginx, didn't work. :c
location / {
if (!-e $request_filename){
rewrite ^(.*)$task_manager/v1/index.php break;
}
}
Please advise me.
phew. Good thing I was only pretending to be dumb.
anyways, so yeah I was trying to make that android REST API work in nginx.
I took a look at another post ( nginx configuration for a RESTful API )
and basically I just needed to change a few things.
original:
rewrite ^/api/v1/([^/]+)/([^/]+)/?$ /apiv1.php?class=$1&method=$2? last;
Edit:
rewrite ^/task_manager/v1/([^/]+)/?$ /task_manager/v1/index.php?method=$2? last;
It seems to work for this specific tutorial. I ran into a different problem with php5-fpm but at least when I use REST Client on chrome it either gives me a 500 error (logs show something in my config isn't parsed correctly) or it will tell me "no there are no users"/"no you are not logged in" but at least this part is solved.
Related
I'm setting up an nginx server this time and wanted to implement my .htaccess from my old apache server.
<IfModule mod_rewrite.c>
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^proc/?$ process.php [NC,L]
</IfModule>
Which describes the following behaviour:
If I browse to http://server.io/proc/, then it should execute process.php , and /proc/ is not a folder!
Nice to have
Also it would be nice, if a direct execution of process.php is disabled - so only via /proc/ allowed.
What did I try already?
I've tried to input in my http.conf and default.conf inside the server{...}:
rewrite ^proc/?$ process.php last;
However thank you guys in advance.
Best Regards
finally after searching the web - I found a simple solution for my first problem.
Solution:
In my http.conf create this inside server{ ... }:
location /proc/ {
rewrite ^/proc/$ /process.php;
}
So, now when I call http://server.io/proc/ process.php will be executed.
First of all, this question has been asked a few times on stack, however, none of the answers seem to work for me.
I have a website which has a "pages" folder in the root, I want to store all of my website pages in there.
Here's my structure
/pages/folder/folder2/index.php
I want to make it so the link displays:
https://wwww.website.com/folder/folder2/index.php
Removing the "/pages/" part of the URL, when I try all of the answers suggested previously, I get a 404 error.
Here is the htaccess I'm using
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^pages(/.*|)$ $1 [L,NC]
</IfModule>
and i also tried:
RewriteEngine On
RewriteRule ^pages/(.*)$ /$1 [L,R=301]
This htaccess is in the root. I can't seem to get it working, can anyone offer any suggestions? Thank you!
Your second attempt looks fine, though it can be imporoved a bit:
RewriteEngine On
RewriteRule ^/?pages/(.*)$ /$1 [R=301]
That rule should work inside the http servers host configuration or in some dynamic configuration file (".htaccess" style file) if the http server's rewriting module is loaded. You definitely should prefer the first option, but if you really need to use a dynamic configuration file then take care that the interpretation of such files is configured at all and that the file is placed in your hosts's DOCUMENT_ROOT folder and is readable for the http server process.
If that does not work then you need to start debugging. In this case you will start by monitoring your http server's error log file while making test requests. If no hint appears in there you need to enable rewrite logging which allows you to learn what exactly is going on inside the rewriting engine. See the official dpcumentation for the apache rewriting module for that. As typcial for OpenSource software it is of excellent quality and comes with great examples.
I wanna make some redirect but for this i need to parse domain to send other domain.
My old domain url like this
http://olddomain.com/bg/some-name-part-421.html
http://olddomain.com/bg/some-name-1231.html
http://olddomain.com/bg/some-name-product-name-221.html
I want to redirect this to like this
https://www.newdomain.com/magazin/some-name-part.html
https://www.newdomain.com/magazin/some-name.html
https://www.newdomain.com/magazin/some-name-product-name.html
I try to redirect them like this on server block
rewrite ^(/bg/)([a-z-]+-[0-9]+)\.html$ http://www.newdomain.com/magazin/$2 permanent;
Not working well making redirect like this
http://www.olddomain.com/bg/chervena-borovinka-bioherba-3694.html
https://www.newdomain.com/magazin/chervena-borovinka-bioherba-3694
I want to delete also as last part of number and - but i dont know why not working well
Thats my .htaccess:
RewriteEngine On
RewriteRule "^bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "http://newdomain.com/magazin/$1$3" [R]
Dont forget to set the RewriteBase.
Heres the code: https://regex101.com/r/UdMqaQ/3/
Nginx
rewrite "^/bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "newdomain.com/magazin/$1";
How can I redirect this URL:
http://domain.com/index.html#!
To this One:
http://domain.com/
Using htaccess rewrite rules?
For /index.html to / you need:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.html
RewriteRule ^ / [R=301,L]
That could incidentally fix the #! part of your URL as well, but that part of the URL is called a fragment, and is added there by something that's on the client side, it stays on the client side, and it is never transmitted to the server. So no htaccess or server side anything is going to know it's even there. If you want to remove it, you need to figure out what script is adding it there and remove the script. If you simply add javacsript to remove it, that other script may inadvertently add it back.
if (location.href.indexOf("#") > -1) {
location.assign(location.href.replace(/\/?#/, "/"));
}
we moved our joomla site and rebuilt. in the process a link got moved that we need to be as it was before.
before:
www.mysite.org/kindergym
now it lives here:
www.mysite.org/education/kindergym
it would seem that it would be easy to go into com_redirect and do this. however, it only works for the following
mysite.org/kindergym without the www
with the www attached writing the old url returns a 404 error page, not a redirect.
i tried to make a separate redirect with the www too and it wouldnt let me. i tried a separate module with no success and have played around with the .htaccess file (although i am not very knowledgeable about htaccess).
could someone explain the reason why this would be an issue? the difference between the two. i tried calling my host and they were less than helpful and actually told me what i wanted to do couldnt be done LOL.
thanks.
I take it the solution you have would work if you redirect the entire mysite.org to www.mysite.org?
If so, create a .htaccess file in the website root. Put the following inside it:
########## Begin - Redirecting non-www request to www
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.org [NC]
RewriteRule (.*) http://www.mysite.org/$1 [L,R=301]
#
########## End - Redirecting non-www request to www
You also need to make sure mod_rewrite is enabled on the apache-server, but I think most providers support that.
I suggest you post your full .htaccess here. However I think all you need is this rule:
RewriteRule ^(?!education/).*)$ education/$1 [L,NC]
The other two answers are good! but better implement 301 redirect in httpd.conf since it's compiled once on server restart. The same code in .htccess is interpreted for each and every HTTP request!