2

I need to rewrite the following url

component/iproperty/?view=property&id=53

to go to

redirect.php?id=53 

using the .htaccess file

the id=53 can be any id at all (always a number)

0

4 Answers 4

2

In your .htaccess ...

RewriteEngine On
RewriteRule ^component/iproperty/?view=property&id=([0-9]+)?$  redirect.php?id=$1 [L]
Sign up to request clarification or add additional context in comments.

7 Comments

This won't work, because the query string isn't tested against the regex in a RewriteRule
but it does work! thought to be fair, @rukmi-patel got it even better with "&id=(\d+)?$"
Hmm.. you're right. It does work! Weird, I've read a few articles on not being able to match against query strings like that and mine works too even though I match $ before the query string. Now I'm confused haha
you definitely know more about .htaccess than i do. is there a performance improvement with your method, or is it just a different approach?
It's just different. Your's might perform slightly faster even since it only has one regex to match against instead of two, but the difference would be nanoseconds.
|
2

This wil do exactly what you asked for:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^view=property&id=(\d+)
RewriteRule ^component/iproperty/?$ /redirect.php?id=%1 [L]

Change [L] to [R=301,L] if you want it to redirect the user's browser.

Comments

0

This should do the trick:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^component/iproperty/?view=property&id=([0-9]+)?$  redirect.php?id=$1 [L]

Comments

0
RewriteRule ^component/iproperty/?view=property&id=(\d+)?$  redirect.php?id=$1 [L]

Comments

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.