[英]How to remove middle part from URL - mod_rewrite
如何在htaccess文件中將此網址“www.domain.com/index.php?route=custom/static/page”重寫為“www.domain.com/page”,基本上只想取出index.php?route =自定義/靜態/來自網址。
我不知道正則表達式,所以我嘗試了http://www.generateit.net/mod-rewrite/ ,但它只生成
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
哪個不從URL中刪除'custom / static',我還嘗試了其他一些例子,但只刪除了index.php? 並沒有傳遞變量,任何幫助表示贊賞。
你知道使用mod-rewrite的概念嗎?
在您提出的問題中,您提到使用mod-rewrite進行重定向
“www.domain.com/index.php?route=custom/static/page”,這里
$_Get['route']="custom/static/page"
]$url_parameter=$_Get['route']
至
“www.domain.com/page”[這里$ _Get ['route'] =“page”],
所以現在你可以手動將“custom / static /”添加到$_Get['route'].
獲得的值中$_Get['route'].
as $url_parameter="custom/static"+$_Get['route'] //For PHP
使用mod_rewrite可以滿足您的需求,
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
但是如果您需要使用.htaccess的開箱即用解決方案,那么我建議學習“重寫引擎”而不是使用生成工具
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.