1

This may be a basic question regarding RewriteRule but I just counldn't make it work.

What I want to do is detect urls like:

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

The part that I need to discart is from the /id/[all this]?param=somethingIdoUse and use the param if is possible or send the complete url as param so I can regex to get the param.

And have a rule that detect that /id/ exist and redirect to something like:

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

(the params I could get the whole url and strip it as string is no problem)

As well the application have different modules like:

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

This have to keep working the same.

As far I've tried some of them like:

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]

But nothing seamed to do kind of what I needed.

Thanks in advice

2 Answers 2

2

mydomain/myapp/id/some/random/url.html?param=somethingThatIdoUse

Here is an example using the above URL:

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

The query will be passed through unchanged to the substitution URL

Sign up to request clarification or add additional context in comments.

3 Comments

I cant make it work with "/myapp/other/manageRequest.php" but if I replace that for index.php (for instance) it works redirects to index.. but adds the prefix of "id/some/random/index.php" so it doesnt find the match. as well I've tried for example with RewriteRule ^.*$ index.php [NC,L] and whenever I enter /some/a/.. is added to the redirected url
ups my mistake it works it does redirect ...now the thing is that I do want it to be a little more dynamic seance /id/[is constant] but the rest of the url is not .. I mean as it could be some/random/ could be anything that the user wants.. is not controlled by my end to add the rule. so it would be eliminate whatever the user enter between "/id/" and "param?[this value is dynamic as well could be any value]"
Thanks you point me in the right direction I end up using: "RewriteRule ^.*id.*$ handleRequest.php [NC,L]" this search for id and redirects!
1

well actually end up being really basic it worked with:

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

I do get the params as they are sent!

1 Comment

+1 Glad you figured out how to modify the rule to meet your requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.