Mobile app version of vmapp.org
Login or Join
Jessie594

: NGINX Rewriting Question How would I convert the following Apache rule RewriteRule ^watch/([A-Za-z0-9-]+)/?$ watch.php?v= [NC] into the appropriate format for an NGINX configuration file? Further

@Jessie594

Posted in: #Apache #Nginx

How would I convert the following Apache rule

RewriteRule ^watch/([A-Za-z0-9-]+)/?$ watch.php?v= [NC]


into the appropriate format for an NGINX configuration file?

Further edit:

server {
listen 80;
listen [::]:80;

server_name domain.tld domain.tld; root /var/www/ROOT;
index index.php index.html index.htm;

return 302 www.domain.tld$request_uri;
location / {
#
# HIDE PHP EXTENSION
#
try_files $uri $uri/ @extensionless -php;
}


location /watch.php {
rewrite ^/watch/([A-Za-z0-9-]+)/?$ /watch.php?v=;
}

#
# HIDE PHP EXTENSION
#
location @extensionless -php {
rewrite ^(.*)$ .php last;
}

#
# BLOCK REFERRER URLS
#

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

error_page 401 /error_pages/401.php;
error_page 403 /error_pages/403.php;
error_page 404 /error_pages/404.php;
error_page 405 /error_pages/405.php;
error_page 408 /error_pages/408.php;

location ^~ /error/ {
internal;
root /error_pages/;
}

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cugini213

The URI in nginx includes the leading /, so the equivalent rewrite would be:

location /watch/ {
rewrite ^/watch/([A-Za-z0-9-]+)/?$ /watch.php?v= last;
}



Would that go in the location / { } block?


That is a slightly more complicated question, and it depends on the nginx configuration, particularly what other location blocks exist.

The options are:


Place it near the top of the server container (outside a location
block)
Place it in the / location
Place it in a /watch location

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme