2013-04-12 84 views
1

這可能是一個關於RewriteRule的基本問題,但我只是沒有使它工作。PHP RewriteRule檢測url是否包含「string」並替換

我想要做的是檢測像URL:

mydomain/myapp/id/some/random/url.html?param=somethingThatIdoUse 
mydomain/myapp/id/other/randomabc/perrito.php?param=somethingThatIdoUse 
... 

,我需要discart從/id/[all this]?param=somethingIdoUse如果可以用參數或發送完整的URL爲PARAM所以我的正則表達式的一部分得到參數。

並具有檢測/id/存在並重定向到類似的規則:

mydomain/myapp/other/manageRequest.php?params=somethingThatIdoUse 

(在PARAMS我能得到整個URL和剝奪其作爲字符串是沒有問題的)

除了應用程序有不同的模塊,如:

mydomain/myapp/moduleOne/index.php 
mydomain/myapp/moduleTwo/index.php 

這必須保持相同的工作。

據我已經嘗試了一些他們的喜歡:

RewriteEngine On 
RewriteCond %{THE_REQUEST} ^GET /.*;.* HTTP/ 
RewriteCond %{QUERY_STRING} !^$ 
RewriteRule .* http://localhostdev/app/index.php %{REQUEST_URI}? [R=301,L] 


RewriteEngine On 
RewriteBase /spt/ 
RewriteCond %{REQUEST_FILENAME} !^id$ [NC] 
RewriteRule ^(.*)$ index.php [R=301,L] 

RewriteEngine On 
RewriteCond %{REQUEST_URI} !/campaings/response\.php$ 
RewriteRule ^/something/(.*) /other/manageRequest.php? [L] 

但沒有接縫做那種我所需要的。

感謝建議

回答

2

MYDOMAIN/MyApp的/ ID /一些/無規/ url.html PARAM = somethingThatIdoUse

這裏是利用上述URL的示例:

RewriteRule ^id/some/random/url.html/? /myapp/other/manageRequest.php [L,NC] 

查詢將通過原樣傳遞給替換URL

+0

我不能讓它與「/myapp/other/manageRequest.php」一起工作,但是如果我將它替換爲index.php(例如)它將重定向到索引..但添加了「id/some/random /index.php「,所以它找不到匹配。 以及我試過例如 RewriteRule ^。* $ index.php [NC,L]和每當我輸入/ some/a/..被添加到重定向的網址 – cesaregb

+0

** ups我的錯誤是有效的它確實重定向** ...現在的事情是,我希望它是一個更動態的seance/id/[是常量],但其餘的url不是..我的意思是,它可能是一些/隨機/可以是用戶想要的任何東西..不受我的端添加規則的控制。所以它會消除無論用戶在「/ id /」和「param之間輸入什麼?[這個值是動態的,也可以是任何值]」 – cesaregb

+0

謝謝你指出我在正確的方向我最終使用: 「RewriteRule^。* id。* $ handleRequest.php [NC,L]「這個搜索* id *並重定向! – cesaregb

1

實際上最終是真正的基本它的工作:

RewriteRule ^.*id.*$ handleRequest.php [NC,L] 

我確實得到它們發送的參數!

+0

+1很高興你知道如何修改規則來滿足你的要求。 –