NGINX domain rewrite rules - mod-rewrite

What I am trying to achieve using nginx is this:
http://domain.com - redirects to http://otherdomain/page.html
http://www.domain.com - redirects to http://otherdomain/page.html
http://domain.com/* - redirects to http://otherdomain/*
Basically only the domain and the www should be redirected to an url link. Everything else should be redirected to another domain, but keeping the url like this:
http://domain.com/subdomain/page.html -> http://otherdomain/subdomain/page.html
If you have questions please let me know. Thank you!

You can use $request_uri
see in http://nginx.org/en/docs/varindex.html
Probably like below
server{
location = /
{
rewrite ^ http://otherdomain/page.html;
}
location /subdomain
{
rewrite ^ http://otherdomain/$request_uri;
}
}

Related

Codeigniter url routing query string

i need to routing my website url to seo friendly url, get out this issue?
please check the screen shot.
http://prntscr.com/ke8uf0
Try this. In routes.php:
$route['products/(:any)'] = 'products/index/$1';
In your controller:
public function index($product_name) { ... }
In folder applicaion -> config-> routes.php
$route['badrumsutrustning/(:any)'] = 'products/index/$1';

Redirect a website url to another website url - GoDaddy

I have a domain let say xyz.com, and I have an internal URL like this, xyz.com/testUrl. I need to redirect this URL (xyz.com/testUrl) to another web site URL.(which is URL like this ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com:3001/employee).
Now, whenever someone hits xyz.com/testUrl , he should be redirected to ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com:3001/employee.
I am using goDadddy hosting.
Just create .htaccess file in web root of xyz.com with content:
Redirect 302 /testUrl xxx.compute-1.amazonaws.com:3001/employee
This will do the required work.
#RequestMapping(value = "/xyz.com/testUrl", method = RequestMethod.GET)
public ModelAndView method() {
return new ModelAndView("ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com:3001/employee");
}

Laravel quick start guide route return 404

So I am a new Laravel user,I just went straight to the documentation to get started.but I get a question:
In app/routes.php,I write like this:
Route::get('users',function() {
return 'hello';
});
Route::get('/',function() {
return View::make('hello');
});
When I hit
127.0.0.1/aerial/public/
it works fine;When hit:
127.0.0.1/aerial/public/index.php/users or 127.0.0.1/aerial/public/users or localhost/aerial/public/index.php/users
it returns 404;My environment nginx.
You should probably convert your .htaccess file in public directory to nginx format and make sure you have mod rewrite (or nginx module used for that) enabled

how to process dynamic urls as static pages using nginx?

I want my Nginx serve dynamical urls as static pages, e.g.
given a url "/book?name=ruby_lang&published_at=2014" ,
the nginx will serve a static file (which is generated automatically ) named as:
"book?name=ruby_lang&published_at=2014.html" or:
"book-name-eq-ruby_lang-pblished_at-eq-2014.html"
is this possible?
NOTE:
1.there's no static file named:
"book?name=ruby_lang&published_at=2014.html" nor
"book-name-eq-ruby_lang-pblished_at-eq-2014.html"
however, I can generate them if needed.
2.I can't change the url that give to the consumer. e.g. my consumer could only send request to me via
"/book?name=ruby_lang&published_at=2014"
but not with any other urls.
If you are OK with generating the HTML files yourself, you could simply use nginx's rewrite module. Example:
rewrite ^/book book-name-eq-$arg_name-published_at-eq-$arg_published_at.html last;
If you need to make sure that name and published_at are valid, you can instead do something like this:
location = /book {
if ($arg_name !~ "^[A-Za-z\d_-]+$") { return 404; }
if ($arg_published_at !~ "^\d{4}$") { return 404; }
rewrite ^/book book-name-eq-$arg_name-published_at-eq-$arg_published_at.html last;
}
This will make sure that published_at is a valid 4-digits integer, and name is a valid identifier (English alphabets, numbers, underscore, and hyphen).
To make sure a book is only accessible from one URL, you should throw 404 if the URL is the HTML file. Add this before the previous rule:
location ~ /book-(.*).html {
return 404;
}
OK, thanks to #Alon Gubkin's help, finally I solved this problem, (see : http://siwei.me/blog/posts/nginx-try-files-and-rewrite-tips) .here are some tips:
use 'try_files' instead of 'rewrite'
use '-' instead of underscore '_' in your static file names, otherwise nginx would get confused when setting $arg_parameters to your file name. e.g. use "platform-$arg_platform.json' instead of "platform_$arg_platform.json"
take a look at nginx built-in variables.
and this is my nginx config snippet:
server {
listen 100;
charset utf-8;
root /workspace/test_static_files;
index index.html index.htm;
# nginx will first search '/platform-$arg_platform...' file,
# if not found return /defautl.json
location /popup_pages {
try_files /platform-$arg_platform-product-$arg_product.json /default.json;
}
}
also I put my code on github so that someone interested in this issue could take a look:
https://github.com/sg552/server_dynamic_urls_as_static_files

how to protect joomla administrator folder?

index.php
$admin_cookie_code="1234567890";
setcookie("JoomlaAdminSession",$admin_cookie_code,0,"/");
header("Location: /administrator/index.php");
.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/administrator
RewriteCond %{HTTP_COOKIE} !JoomlaAdminSession=1234567890
RewriteRule .* - [L,F]
i used this code but it's not working...
page will be redirect to administrator but www.domain.com/administrator is also accessable
I got tired of searching an answer for this one and just made a PHP code that will redirect if the visitor gets into the /administration folder without the security key or as a registered user:
Just place this code at the end of the index.php file on your administration folder (/administration/index.php) before the 'echo' instruction:
/* Block access to administrator
--------------------------------------------- */
$user =& JFactory::getUser();
$secretkey = 'mysecretkey';
$redirectto = 'location: yourdomainurlhere';
$usertype = 'Registered';
//Check if the user is not logged in or if is not a super user:
if ($user->guest || (!$user->guest && $user->usertype != $usertype) ) {
//Check if the secret key is present on the url:
if (#$_GET['access'] != $secretkey) { header($redirectto); }
}
/* --------------------------------------------- */
After you will be only able of accessing your site using:
mysite.com/administrator/?access=mysecretkey
Tested on Joomla 1.5 and Jooma 2.5, worked well for both.
I explain it a little bit more on my page:
https://www.infoeplus.com/protect-your-joomla-administrator-folder/
Are you trying to hide the administrator URL ? Here is what I'm using :
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection/15711
You can find more extensions here : http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
http://extensions.joomla.org/extensions/access-a-security/site-security/login-protection
you can use this protect your admin login.
this is really esay and nice extension.

Resources