1

I have this url: http://example.org/product.php?course_id=$x

And I want this url changes to this: http://example.org/Course-Name

this is my code in .htaccess file:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^  404page.php
RewriteRule ^/([0-9]+)/([^/]+)/$ /product.php?course_id=$1 [L,R]

Which is not working kindly tell me whats wrong with my code?

5
  • You would need a matching redirect, not just a rewrite. Currently you're letting the server understand the user-friendly URL but not redirecting to that user-friendly one from the real URL. NB the links in your HTML should be the ones you want to see, not the real ones that would then be redirected. Commented Dec 23, 2013 at 12:40
  • Is your .htaccess processed? Check in apache config if your directory has AllowOverride all Commented Dec 23, 2013 at 12:42
  • ok i change rewrite to redirect but still not working Commented Dec 23, 2013 at 12:43
  • yes its AllowOverride all Commented Dec 23, 2013 at 12:47
  • popnoodles kindly tell me how to redirect? i dont know exact syntax Commented Dec 23, 2013 at 12:49

1 Answer 1

1

You need to remove leading slash from your rule. Try this rule:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+product\.php\?course_id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /product.php?course_id=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

Which URL isn't working and what is location of this .htaccess and your product.php files?
Did you delete your comment?
ops accidently i did, but thanku so much for your time it works now :))

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.