I am new to nginx, and i would like to know from where I can start URL rewrite in nginx,
I know with apache we can have .htaccess file. but for whenever I have search for ngingx i just get the rules and syntax and all that. But i would like to know in which file I have to write these rules just like .htaccess file for apache.
nginx doesn't have an equivalent to .htaccess files, you need to put the rewrite rules in the server config.
Related
I want an old website to be redirect to the new one, the URL looks like this : https://test.fr/directory/homepage.html
In my .htaccess file I have :
RedirectPermanent / https://google.com/`
But what it does : https://google.com/directory/homepage.html
I'd like to redirect to https://google.com/ and delete everything after the .com/ but I have no idea how.
Just use the rewriting module:
RewriteEngine on
Rewrite ^ https://google.com/ [R=301,END]
Obviously the rewriting module needs to be loaded into the http server for that. This usually is the case, certainly for all hosting providers.
If you only want to redirect that specific URL inside your http host, then that should do:
RewriteEngine on
Rewrite ^/?directory/homepage\.html$ https://google.com/ [R=301,END]
You can implement such directives in a distributed configuration file (".htaccess"). You should prefer the actual http server's host configuration though, if you have access to that.
Will .htaccess files still work if Nginx is running (along with Apache), or do I need to disable Nginx for them to work?
Thanks!
.htaccess is an Apache config file. Nginx doesn't use it (file is ignored and treated like any other), and Apache config rules don't apply to Nginx.
I am just started looking into using Nginx over Apache into my own LAMP stack. But I use a number of frameworks (CakePHP) which use .htaccess files.
What I don't understand is if I need to convert theses files into something else?
.htaccess will not be useful to nginx. You need to convert them to /etc/nginx/nginx.conf like files.
Here is a start for pretty URLs with CakePHP (official doc):
http://book.cakephp.org/2.0/en/installation/url-rewriting.html#pretty-urls-on-nginx
Note: generally, you'll add a yoursite.conf file in /etc/nginx/sites-enabled/
So i've a Wordpress site on my domain and i want to add subdomains with their own php code. I'm using mod_rewrite for wordpress and want to use it for my own projects but weirdly i can access urls that should result in a 404 error. For example i can access test/somestuff/morestuff and get test.php (without any $_GET set). But i have no .htaccess file in the directories for the virtual hosts. I then tried to delete the .htaccess from wordpress, restart apache2, and try again but i get the same behavior on the virtual host and wordpress doesn't work with permalinks (like i thought it would). My sites-available configs don't have any rewrite rules in them. Why can i access URLs that shouldn't work? Am i missing some feature of apache?
So after some more trying i've discovered the error was that i've had MultiViews enabled for the virtual host. I've disabled it and now it works.
I have a site that I am running in Apache that is static and I want the server to treat each file as a directory. I have this thing set up in .htaccess that will get rid of all .html extensions. So this is what I want:
Ex.
http://example.com/about (Currently)
to
http://example.com/about/
without having to change it into a directory or make it dynamic. Is there a .htaccess hack? Is it possible?
You should check out mod_rewrite which lets you rewrite any url using regular expressions.