Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess-重定向所有.html捕获ID_.htaccess_Laravel 5 - Fatal编程技术网

.htaccess-重定向所有.html捕获ID

.htaccess-重定向所有.html捕获ID,.htaccess,laravel-5,.htaccess,Laravel 5,我面临以下问题: 我有一个网站,其中的URL当前看起来像: /manufacturer/product/[ID].html 我已经重新开发了网站(使用Laravel),现在它只是: /product/[ID] 我想知道是否可以使用.htaccess文件将所有这些链接重定向回新链接?因此,本质上,我只需要从旧链接捕获[ID]并将其重定向回新链接 编辑: 因此,链接将如下所示: mysite.com/parts/apple/A-6-H0.htm 或 因此,Apple、Microsoft和A-都

我面临以下问题:

我有一个网站,其中的URL当前看起来像:

/manufacturer/product/[ID].html
我已经重新开发了网站(使用Laravel),现在它只是:

/product/[ID]
我想知道是否可以使用.htaccess文件将所有这些链接重定向回新链接?因此,本质上,我只需要从旧链接捕获[ID]并将其重定向回新链接

编辑:

因此,链接将如下所示:

mysite.com/parts/apple/A-6-H0.htm

因此,
Apple
Microsoft
A-
都可以根据制造商和产品的不同而变化,这有意义吗

RewriteEngine On
RewriteRule ^parts/(?:[^/]+/)?(.*)\.html?$ /parts/$1/ [R=301,L]
那就可以了。

请试试这个:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^{domain name}[nc]
RewriteRule ^(.*)$ {domain name}/$1 [r=301,nc]   
Redirect 301 /manufacturer/product/$1.html product/$1.html

它不起作用,因为有一个
/manufacturer
。。我需要忽略这一点。。目前,它将从:
/manufacturer/product/[ID].htm
重定向到:
/manufacturer/product/[ID]
,因此works@Phorce如果
制造商
始终存在(后跟产品),则上述代码应将您重定向到
/product/ID
页面,并删除制造商!=)非常抱歉。链接应该是:/manufacturer/product/[ID].htm-但是制造商可以是任何类似于苹果、微软的东西,所以我想完全删除它。。对不起,它将是这样的:
/product/[manufacturer]/[product\u ID]
-我可以这样做吗?我需要删除[MANUFACTURER]和[PRODUCT_ID],并重定向到
/
@Phorce您可以编辑您的问题,并放置一些“实际”链接和最终重定向链接吗?@mayank-而且,它不会总是/MANUFACTURER/
/MANUFACTURER/
是一个变量。。可能是苹果、微软等。你的htaccess在/manufacture文件夹中吗?@starkeen不,这是一个laravel项目.htaccess文件在/public中,
mysite.com/parts/Apple/a-6-H0.htm
重定向到?@hjpotter92-刚刚返回
mysite.com/parts/a-6-H0/
@hjpotter92这有意义吗?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^{domain name}[nc]
RewriteRule ^(.*)$ {domain name}/$1 [r=301,nc]   
Redirect 301 /manufacturer/product/$1.html product/$1.html