2012-12-17 42 views
0

任何QUERY_STRING發送到我的index.php要發送的所有ADRESS網址在我的域名作爲我如何通過htaccess的

QUERY_STRING到根目錄下的用戶類型index.php文件

帶參數的URL,其= QUERY_STRING

如果例如用戶類型www.mydomain.com/abc/123

它將www.mydomain.com/index.php/?url=abc/123

我的HT訪問代碼不發送參數的URL我不知道爲什麼:

# Use PHP5 Single php.ini as default 
AddHandler application/x-httpd-php5s .php 

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

我的PHP文件:

<?php 

    if ($GET['url']){ 
     $url = $GET['url']; 
     echo ($url.'<br />'); 
    } 
?> 
we are in root directory. 

千恩萬謝

回答

1

我建議加入[NE]標誌的重寫規則

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,NE] 

這將確保您的問號不會被轉義。

我對你的RewriteCond條件有點困惑。正則表達式應該匹配任何可能的字符串,包括一個空字符串,所以應該始終傳遞條件。

0

它在$_SERVER$_SERVER['QUERY_STRING']

+0

我的問題是,當用戶鍵入QUERY_STRING htaccess不發送QUERY_STRING到index.php你可以在這裏看到它[http://kidslearning4fun.com/](http://kidslearning4fun.com/) – rotem

+0

沒關係我的回答,閱讀troelskn的答案,我意識到我誤解了這個問題。對不起;) –

0

需要使它成爲一個查詢字符串參數嗎?否則,只需將他請求重定向到index.php並在php中使用$_SERVER['REQUEST_URI'],這將包含原始請求的路徑。

這裏有一個.htaccess規則,會爲這項工作:

DirectoryIndex index.php 

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [L] 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^.*$ - [L] 

RewriteRule ^.*$ index.php [L] 
+0

是這是正確的代碼,但我想QUERY_STRING即使它不是文件或目錄在所有情況下,我想要QUERY_STRING – rotem

0
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] 

它將作品..