2013-04-12 85 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很高兴你知道如何修改规则来满足你的要求。 –