简体   繁体   English

从网址htaccess删除第二个目录

[英]Remove second directory from url htaccess

Hi guys I would like to remove the second directory from a url like https://www.example.com.au/products/mopod/MP15/ ? 嗨,大家好,我想从https://www.example.com.au/products/mopod/MP15/这样的网址中删除第二个目录吗? to https://www.example.com.au/products/MP15/ ? https://www.example.com.au/products/MP15/

by the way /mopod/MP15 is generated by a plugin. 通过插件生成/ mopod / MP15的方式。

Assuming you are using Apache, you must first enable .htaccess and mod_rewrite in your httpd.conf . 假设您正在使用Apache,则必须首先在httpd.conf启用.htaccessmod_rewrite

Then, you can rewrite a URL to "remove" a given directory by adding the example below to your .htaccess in the DOCUMENT_ROOT . 然后,您可以通过在DOCUMENT_ROOT.htaccess中添加以下示例来重写URL以“删除”给定目录。 In this example, mopod is the folder you wish to be hidden: 在此示例中, mopod是您希望隐藏的文件夹:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/products/mopod/(.*)$ /products/$1 [L,NC,R]

Explanation: The above rules find any URL matching products/mopod/*, and move the files at * into $1's location. 说明:上面的规则找到任何与product / mopod / *匹配的URL,并将*处的文件移动到$ 1的位置。 We then make a redirection to /products/$1. 然后,我们重定向到/ products / $ 1。

These are the flags used:
L  - Last
NC - No Case comparison
R  - External Redirection

For completion sake, because you have not specified what web server you are using, an example for IIS is also given below (whereby mopod is the folder to be removed). 为了完整起见,由于您尚未指定要使用的Web服务器,因此下面还会提供IIS的示例(其中mopod是要删除的文件夹)。 You can ignore this if my assumption that you are using Apache is correct. 如果我假设您使用的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>

I see that you are new to Stack Overflow. 我看到您是Stack Overflow的新手。 Welcome! 欢迎!

If this answers your question please remember to mark my answer as correct. 如果这回答了您的问题,请记住将我的回答标记为正确。 Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM