Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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特定类型URL的规则_.htaccess - Fatal编程技术网

.htaccess特定类型URL的规则

.htaccess特定类型URL的规则,.htaccess,.htaccess,你能帮我完成这项工作吗 http://domain.com/gallery/category/another/slug 到 如果URL包含单词gallery,并且无论其余部分是什么,它都会将请求发送到http://domain.com/gallery/ http://domain.com/gallery/category/another/slug -> will hit http://domain.com/gallery/ http://domain.com/gallery/anothe

你能帮我完成这项工作吗

http://domain.com/gallery/category/another/slug

如果URL包含单词
gallery
,并且无论其余部分是什么,它都会将请求发送到
http://domain.com/gallery/

http://domain.com/gallery/category/another/slug -> will hit http://domain.com/gallery/
http://domain.com/gallery/another/slug -> will hit http://domain.com/gallery/
http://domain.com/gallery/more/more/slug -> will hit http://domain.com/gallery/
当前我现有的.htaccess如下所示-

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基地/站点/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/site/index.php[L]
#结束WordPress

如果您希望将每个库URL重写为
/gallery/
,您只需执行以下操作即可

RewriteRule ^gallery/.* /gallery/ 
它将在主机名处查找路径以(
^
)单词
gallery
开头,后跟任何(
*
)的URL,并将其重写为
/gallery/

如果要停止计算其他规则,可以添加两个标志--
[L]
,如果不应该区分大小写,可以添加两个标志--
[NC]


如果要将此添加到一组现有规则中,可能需要处理订单

谢谢你的回答。您可以看到我当前的.htaccess文件。我在第
行“重写规则”之前添加了
重写规则^gallery/*/gallery/[L]
/site/index.php[L]
显示未找到的对象!如果我添加
RewriteRule^gallery/*/site/gallery/[L]
则显示内部服务器错误。你有什么建议吗?有吗?另外,
[L]
指示这应该是执行的最后一条规则。这可能不是你想要的。查看或了解详细信息如果存在domain.com/gallery,我只想显示domain.com/gallery页面内容,如果用户点击domain.com/gallery或domain.com/gallery/more或domain.com/gallery/more/slugh,当您说“它显示”或“它正在显示”时,您是指浏览器吗?URL是否更改?没有URL未更改。另外,我也不想更改url
RewriteRule ^gallery/.* /gallery/