0

i am trying to rewrite a URL for SEO purpose.

The old URL is:

http://www.example.com/recipe_local.php?hl_cusine=1

The new URL should be like bellow and automatic redirect to this url if user come above url

http://www.example.com/recipes/healthy-recipes

My Code in the .htaccess is:

RewriteEngine on
RewriteRule ^recipes/healthy-recipes/$ recipe_local.php?hl_cusine=$1 [NC,L]
RewriteRule ^recipes/healthy-recipes$ recipe_local.php?hl_cusine=$1 [NC,L]

Even after hours of research, i have no clue why this is not working :(

3
  • What URL are you going to and what are you expecting to see? Commented Feb 18, 2015 at 5:22
  • How can healthy-recipes become hl_cusine=1 in rewrite rules only? Commented Feb 18, 2015 at 7:40
  • You are trying to do things at once (as people frequently do in this scenario). First, you want to make it so that when a user types in http://www.example.com/recipes/healthy-recipes/42, it acts as though they typed http://www.example.com/recipe_local.php?hl_cusine=42 (internal rewrite). Second, with a completely different rule, you want to make it so that when a user actually types http://www.example.com/recipe_local.php?hl_cusine=42, their browser is told to instead load http://www.example.com/recipes/healthy-recipes/42 (external redirect). Commented Feb 18, 2015 at 12:49

1 Answer 1

1

The $1 in your rewrite is pointing to a backreference you never capture.
Unless you have a RewriteCond you are not showing?
try:

RewriteEngine on
RewriteRule ^recipes/healthy-recipes/$ recipe_local.php?hl_cusine=1 [NC,L]
RewriteRule ^recipes/healthy-recipes$ recipe_local.php?hl_cusine=1 [NC,L]
Sign up to request clarification or add additional context in comments.

3 Comments

@Michael...now url is opens like example.com/recipes/healthy-recipes but its not redirect automatically
can you explain a bit more?
I am trying to add in pagination...so it will take parameter from url and make dynamic url example.com/recipe_local.php?page=2&hl_cusine=1 to example.com/recipes/healthy-recipes/1

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.