Apache 最终版本中带编号的nginx重写规则
有人能在nginx上或使用.htaccess帮助我解决这个问题吗 我想重定向一个url,如:Apache 最终版本中带编号的nginx重写规则,apache,.htaccess,mod-rewrite,nginx,rewrite,Apache,.htaccess,Mod Rewrite,Nginx,Rewrite,有人能在nginx上或使用.htaccess帮助我解决这个问题吗 我想重定向一个url,如: [http][www]domainName.tld/folderName/a-name-with-dashes-15-and-numbers-and-a-number-of-at-least-5-digits 变成 [http][www]domainName.tld/newFolderName/a-name-with-dashes-15-and-numbers 或 有www或没有www。 没有域的更
[http][www]domainName.tld/folderName/a-name-with-dashes-15-and-numbers-and-a-number-of-at-least-5-digits
变成
[http][www]domainName.tld/newFolderName/a-name-with-dashes-15-and-numbers
或
有www或没有www。
没有域的更真实示例:
/folderName/test-1-test-again-123456789
变成
/newFolder/test-1-test-again
# or
/test-1-test-again
非常感谢
@稍后编辑:从服务器块添加Nginx配置
listen ip:80;
server_name domain.tld www.domain.tld;
root /var/www/domain.tld/web;
if ($http_host = "www.domain.tld") {
rewrite ^ $scheme://domain.tld$request_uri? permanent;
}
index index.html index.htm index.php index.cgi index.pl index.xhtml;
error_log /var/log/domain.tld/error.log;
access_log /var/log/domain.tld/access.log combined;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client/web/web/stats/.htpasswd_stats;
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files /c91e3e9dc234ca8eec5e7e5309e2fcca.htm @php;
}
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web24.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
client_max_body_size 20M;
location ~* ^.+\.(css|png|ico|ttf|rss|atom|js|jpg|jpeg|gif|zip|tgz|gz|rar|bz2|doc|xls|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
add_header Pragma public;
add_header Cache-Control: public;
}
location ~* ^/wp-admin/.*.(html|htm|shtml|php)$ {
client_max_body_size 30M;
}
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain;
}
location ~* ^/static/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* (wp-comments-posts|wp-login)\.php$ {
if ($http_referer !~ ^(http://www.domain.tld) ) {
return 405;
}
}
试试这样的
location ~ '(.*)\-[0-9]{5,}$' {
return 301 $scheme://$server_name$1;
}
这应该去掉所有尾随数字,如果url末尾的数字超过5个首先,nginx不支持.htaccess,那么您是使用nginx还是使用apache?我知道nginx不支持.htaccess。我需要nginx,但如果有人能帮我。htaccess不是问题,因为我会转换它。谢谢你在寻找ApacheAnswer或nginx,你标记了bothI知道,我已经标记了这两个。我需要nginx的答案,但是如果有人能给我.htaccess的答案也可以,因为我可以将规则从.htaccess转换为nginx,或者从.htaccess转换为nginx,我也会在这里发布。我对一个可以重定向的规则感兴趣。很抱歉我问你,这应该只适用于复制+粘贴?或者我需要换点别的?我这样问是因为,如果我在配置文件中复制+粘贴,nginx不会启动。非常感谢。运行sudo nginx-t,并告诉我输出您是否可以将您当前的nginx配置添加到问题nginx-t输出:nginx:[emerg]未知指令5,}$in/etc/nginx/sites enabled/100 domain.tld.vhost:55 nginx:configuration file/etc/nginx/nginx.conf测试失败了很多,现在可以工作了!正如我之前所说,我将把它转换成.htaccess并发布。
location ~ '(.*)\-[0-9]{5,}$' {
return 301 $scheme://$server_name$1;
}