1

I tried using this code:

RewriteRule ^(.*)/([0-9a-zA-Z]+) results.php?property_type=$1&city=$2 [NC,L]

I want to redirect all of my property types and city. Example:

domain.com/apartment/doha

But it seems that it is now working, the js, css, images or any includes are returning an error.

What is the best approach for this?

Thanks!

1 Answer 1

1

First thing fix your rule's regex by having this in root .htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ results.php?city=$1&property_type=$2 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ results.php?city=$1 [QSA,L]

Then add this in the <head> section of your page's HTML:

<base href="/" />

so that every relative URL is resolved from that URL and not the current page's URL.

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

2 Comments

Hi @anubhava, Thanks! it works! but I have one more problem. I changed it to domain.com/doha/apartment But I need to be domain.com/doha too but i have a rewrite rules like this: RewriteRule ^privacy-policy privacy-policy.php [NC,L] RewriteRule ^commercial results.php?page=commercial [NC,L] RewriteRule ^buy results.php?forwhat=sale [NC,L] RewriteRule ^rent results.php?forwhat=rent [NC,L] RewriteRule ^results results.php [NC,L] RewriteRule ^agents agent.php [NC,L] it conflicts with the rules you gave me. What should I do with this? Thanks!
Keep those specific rules before my suggested rule. And also see updated rules.

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.