By milstanyu
Hello,
I am using LEMP droplet. For SEO purposes, I made redirection from site.com/index.php to site.com like this:
server {
...
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
}
...
}
It works just fine, but I need it to work on root folder of the site only. It currently redirects all folders, in example /folder/index.php will be redirected to /folder/
This prevents some of my scripts to work normally (Joomla backend in example). How can I change the above code and make this redirection for root folder only.
Thanks, Milos
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I have no idea what you seek to achieve with this, but use try_files. That way, unless you are actively using http://foo.bar/index.php in your code, all requests will be evaluated at /.
Something like this:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
If you are doing this because of duplicate content you can rest assure that Google don’t care all that much. Just be consistent in the way you link to your content.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.