2016-09-27 51 views
0

我正在嘗試使用htaccess進行重定向,但不知何故,這似乎不起作用。解析FQDN背後的所有變量作爲變量

我想拿起一切完全限定域名後面,解析它作爲一個變量到PHP,使我的URL的樣子:

https://example.com/?abc.com 

在後臺它應該做的:

https://example.com/index.php?url=abc.com 

類似的東西我已經在做另一個鏈接,但不知何故,這似乎並沒有工作。

RewriteRule ^(.+)$ https://example.com/index.php?url=$1 [L] 

我在做什麼錯在這裏,我開始懷疑這個心不是可能

回答

0

與嘗試:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ https://example.com/index.php?url=$1 [QSA,L] 

QSA | qsappend當更換URI包含查詢字符串,RewriteRule的 默認行爲是放棄現有查詢 字符串,並將其替換爲新生成的字符串。使用[QSA] 標誌會導致查詢字符串被合併。
http://httpd.apache.org/docs/2.2/en/rewrite/flags.html#flag_qsa

您還可以使用:

RewriteRule ^(.+)$ https://example.com/index.php?url=$1%{QUERY_STRING} [L] 

,因爲沒有變量名是不容易使用

+0

可悲的是不工作。它會把大量的index.php?url =後面的fqdn 'https://example.com/index.php?url=index.phpurl=index.phpurl=index.phpurl=index.phpurl=index。 phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.phpurl = index.htmlabc.com' – RvdM

+0

I在代碼中添加對文件和目錄的測試 – Croises