简体   繁体   English

从子目录重定向复杂的.htaccess

[英]Complex .htaccess redirect from subdirectory

Couldn't find an existing question and answer on this one. 找不到有关此问题的现有问题和答案。

How can we redirect from this page: 我们如何从该页面重定向:

http://duh.com/candy-apple/123-main-st-OK-48775/1226460/157/ http://duh.com/candy-apple/123-main-st-OK-48775/1226460/157/

to this one: 对此:

http://duh.com/details?id=1226460 http://duh.com/details?id=1226460

Things to know 要知道的事

  • The only part of the URI that is needed is the 7 digit number. URI唯一需要的部分是7位数字。 It is always found in the same level of subdirectory in the URI. 总是在URI的同一级别的子目录中找到它。
  • There is no way to know what the string will be in either of the first two subdirectories (/candy-apple/123-main-st-OK-48775/) 无法知道前两个子目录(/ candy-apple / 123-main-st-OK-48775 /)中的字符串是什么
  • The # of subdirectories will always be the same prior to the 7 digit number. 子目录的编号将始终与7位数字相同。

Try this rule in root .htaccess: 在根.htaccess中尝试以下规则:

RewriteEngine On

RewriteRule ^[^/]+/[^/]+/(\d+)/.*$ details?id=$1 [L,QSA]

Try out this htaccess rule for redirect 试用此htaccess规则进行重定向

http://duh.com/candy-apple/123-main-st-OK-48775/1226460/157/ http://duh.com/candy-apple/123-main-st-OK-48775/1226460/157/

to

http://duh.com/details?id=1226460 http://duh.com/details?id=1226460

RewriteRule ^candy-apple/([a-zA-Z0-9-_]+)/([0-9]+)/([0-9]+)/?$ details?id=$2 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM