[英]htaccess remove folder redirect
I have a problem removing folders from an url. 我从网址中删除文件夹时遇到问题。 I want that google / old links aren't broken. 我希望Google /旧链接没有损坏。 The old webpage had several sections with a structure like this 旧网页有几个部分,其结构如下
example.com/news/items/entry1.html
example.com/news/items/entry2.html
example.com/blog/items/foo.html
The new page has the urls like this: 新页面具有如下网址:
example.com/news/entry1
example.com/news/entry2
example.com/blog/foo
Removing html was rather straight forward 删除HTML相当简单
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php [QSA,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
</IfModule>
The part I'm struggling with is removing the 'items' part. 我正在努力的部分是删除“项目”部分。 The rules I found only worked for request path like 'example.com/items/subfolder1/...' 我发现的规则仅适用于请求路径,例如“ example.com/items/subfolder1 / ...”
Any help would be greatly appreciated. 任何帮助将不胜感激。
To remove /items/
from your URLs you can use the following in your .htaccess
file: 要从URL中删除/items/
,可以在.htaccess
文件中使用以下命令:
RewriteEngine On
RewriteRule ^(.*)/items /$1 [L,R=301]
So for example, this will take the URL: http://example.com/news/items/entry1 and turn it into http://example.com/news/entry1 因此,例如,它将采用以下URL: http : //example.com/news/items/entry1并将其转换为http://example.com/news/entry1
Make sure you clear your cache before testing this. 在测试之前,请确保清除缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.