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
.htaccess 使用Htaccess删除部分URL_.htaccess_Redirect - Fatal编程技术网

.htaccess 使用Htaccess删除部分URL

.htaccess 使用Htaccess删除部分URL,.htaccess,redirect,.htaccess,Redirect,我需要从这个URL(以及任何包含它的URL)中删除/design/ 最后,我希望它看起来像这样: https://www.domain.com/subcategory/productname1 https://www.domain.com/shirts/ 但由于这显然会导致404人删除URL的这一部分,所以我需要用第一个URL的内容填充第二个URL。我很抱歉,如果我没有使用正确的术语,但这里有一个类似的例子,我在我的网站上 在我的标题菜单中,我有一个链接,指示它将带您到这里: https:/

我需要从这个URL(以及任何包含它的URL)中删除/design/

最后,我希望它看起来像这样:

https://www.domain.com/subcategory/productname1
https://www.domain.com/shirts/
但由于这显然会导致404人删除URL的这一部分,所以我需要用第一个URL的内容填充第二个URL。我很抱歉,如果我没有使用正确的术语,但这里有一个类似的例子,我在我的网站上

在我的标题菜单中,我有一个链接,指示它将带您到这里:

https://www.domain.com/index.php?route=product/search&tag=shirts
但我希望它看起来像这样:

https://www.domain.com/subcategory/productname1
https://www.domain.com/shirts/
所以我研究了它,这个解决方案非常有效:

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+product/search/\?tag=([^\s&]+) [NC]
RewriteRule ^ /%1/? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ product/search/?tag=$1 [L,QSA]
是否可以执行类似的操作来删除URL的/design/部分

谢谢

试试这些规则:

RewriteEngine On

# remove /design/ from URLs and redirect
RewriteCond %{THE_REQUEST} \s/+design/(\S*)\s [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# internally add design/ to know set of URIs
RewriteRule ^(skulls-bones|characters|abstract|animals|games|geek-nerd|graphic|keep-calm|movies-tv|pop-culture|tattoo|typography)(/.*)?$ design/$1$2 [L,NC]

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+product/search/\?tag=([^\s&]+) [NC]
RewriteRule ^ /%1/? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/design/ [NC]
RewriteRule ^([^/]+)/?$ product/search/?tag=$1 [L,QSA]

是的,这是正确的,子类别是将要更改的零件。它的设计类型,所以有一个子类称为“书呆子”,“游戏”,等等。但您不想将
/design/
添加到
/product/search?tag=…
URI中,因此了解将要添加
/design/
的URI列表或不添加
/design/
的URI列表非常重要。我不想在URL中的任何位置添加/design/。以下是当前可以找到的位置:domain.com/design/abstract/domain.com/design/animals/domain.com/design/characters/等。如果我添加一个产品,它会进入其中一个(例如domain.com/design/abstract/product1)。我根本不希望URL中的父类别(/design/),可以删除它并使用htaccess代理内容吗?只是澄清一下,/design/永远不会被添加,以下是我的所有类别:
https://www.domain.com/design/abstract/
https://www.domain.com/design/animals/
https://www.domain.com/design/characters/
https://www.domain.com/design/games/
https://www.domain.com/design/geek-nerd/
https://www.domain.com/design/graphic/
https://www.domain.com/design/keep-calm/
https://www.domain.com/design/movies-tv/
https://www.domain.com/design/pop-culture/
https://www.domain.com/design/skulls-bones/
https://www.domain.com/design/tattoo/
https://www.domain.com/design/typography/
成功了!我对“添加设计/到已知的URL集合,但其他所有内容都是100%的”做了一点调整。非常感谢!这是给其他需要它的人的粘贴箱。这里列出的名称是我的类别-这很好知道。我在回答中更新了这些规则。我注意到一个错误。任何包含“-”的类别都不起作用(例如,“骷髅骨头”或“极客书呆子”)。但是,只要有一个单词就可以了(例如“动物”或“游戏”。知道为什么会发生这种情况吗?htaccess如何查看“-”?谢谢!这些规则中没有特定于连字符的内容。您在浏览器中输入的完整URL是什么,会出现什么错误?