- none -
nginx: Rewrite URL
Visa signatur
Hej, försöker mig på att fixa en rewrite för att få adressen att bli mer lätt läst.
Den ser nu ut så här.
http://domain.com/sites/default/files/image.png
men vill få den att se ut så här ->
http://domain.com/public/images/image.png
Visa bilder är i mappar t.ex. http://domain.com/sites/default/files/portfolio/image2.png
och samtidigt behålla delen "portfolio/image2.png" ->
http://domain.com/public/images/portfolio/image2.png
Kan nämna att det är nginx med Drupal 7. Har försökt flera gånger men förstår inte hur det funkar.
Är det ens möjligt att göra det som jag har tänkt?
Har du läst wikisidan hos Ngix?
http://wiki.nginx.org/NginxHttpRewriteModule
- none -
Flera gånger Men tycker den är väldigt otydlig har även sökt runt på Google.
Här är min config som jag testade senast.
server {
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name www.domain.com domain.com;
access_log /var/log/nginx/localhost.access.log;
root /var/www/domain.com;
access_log /var/log/nginx/YOURDOMAIN.access.log;
error_log /var/log/nginx/YOURDOMAIN.error.log info;
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# This matters if you use drush
location = /backup {
deny all;
}
# Very rarely should these ever be accessed outside of your lan
location ~* \.(txt|log)$ {
allow 127.0.0.1;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ @rewrite;
expires max;
}
location @rewrite {
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
rewrite ^/(.*)$ /index.php?q=$1;
#Mitt senaste försök här nedan
rewrite ^/public/images/(.*).(png|jpeg|jpg|gif)$ /index.php?q=/sites/default/files/$1.$2;
#Ett annat
rewrite ^/sites/default/files/(.*).(png|jpeg|jpg|gif)$ /public/images/$1.$2;
}
Har även testat olika config med hjälp av en separat location{}. Om deras dokumentation var lite tydligare skulle det nog vara lite lättare eller så har jag missat något. Kanske har något med Drupal att göra.
Spelnyheter från FZ
Copyright © 1999–2025 Geeks AB. Allt innehåll tillhör Geeks AB.
Citering är tillåten om källan anges.