[英]Remove second directory from url htaccess
嗨,大家好,我想從https://www.example.com.au/products/mopod/MP15/這樣的網址中刪除第二個目錄嗎? 到https://www.example.com.au/products/MP15/ ?
通過插件生成/ mopod / MP15的方式。
假設您正在使用Apache,則必須首先在httpd.conf
啟用.htaccess
和mod_rewrite
。
然后,您可以通過在DOCUMENT_ROOT
的.htaccess
中添加以下示例來重寫URL以“刪除”給定目錄。 在此示例中, mopod
是您希望隱藏的文件夾:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^/products/mopod/(.*)$ /products/$1 [L,NC,R]
說明:上面的規則找到任何與product / mopod / *匹配的URL,並將*處的文件移動到$ 1的位置。 然后,我們重定向到/ 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的新手。 歡迎!
如果這回答了您的問題,請記住將我的回答標記為正確。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.