嗨,大家好,我想从https://www.example.com.au/products/mopod/MP15/这样的网址中删除第二个目录?到https://www.example.com.au/products/MP15/?从网址中删除第二个目录htaccess
顺便说一下/ mopod/MP15是由插件生成的。
嗨,大家好,我想从https://www.example.com.au/products/mopod/MP15/这样的网址中删除第二个目录?到https://www.example.com.au/products/MP15/?从网址中删除第二个目录htaccess
顺便说一下/ mopod/MP15是由插件生成的。
假设您使用的是Apache,必须先在您的httpd.conf
中启用.htaccess
和mod_rewrite
。
然后,您可以通过将以下示例添加到中的DOCUMENT_ROOT
中来重写URL以“删除”给定的目录。在这个例子中,mopod
是你想要的文件夹被隐藏:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase/
RewriteRule ^/products/mopod/(.*)$ /products/$1 [L,NC,R]
说明:上述规则找不到任何URL匹配产品/ mopod/*,并且在*到$ 1'S位置移动文件。然后我们重定向到/ products/$ 1。
These are the flags used:
L - Last
NC - No Case comparison
R - External Redirection
完成的缘故,因为你没有指定你使用的Web服务器,IIS的一个例子也如下(其中mopod
是要删除的文件夹)。如果我假设你使用Apache是正确的,你可以忽略它。
<system.webServer>
<rewrite>
<rules>
<rule name="removefolder" stopProcessing="true">
<match url="^/products/mopod/(.*)" />
<action type="Rewrite" url="/products/{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
我看到你是Stack Overflow的新手。欢迎!
如果这回答你的问题,请记住标记我的答案是正确的。谢谢。
到目前为止您尝试过什么? – hering