0

I have lot or articles with this URL format:

mydomain/art/details.php?articleid=24463&parentid=1&catid=166

the above is an example.

And i want that redirect these kind of URL to :

mydomain/art/24463.html

Please let me know that how can i do it with .htaccess?

Thanks in advance

16
  • Since parentid and catid are not in your new format url and are dynamic parameters, you can't have a generic rule. You must use RewriteMap or write a rule by url. Or you can add thoses params to your new format url and then it will be possible to write a generic rule Commented Apr 21, 2015 at 15:29
  • thanks,but i'm not familiar with rules in .htaccess ,please let me know how can i do it? Commented Apr 21, 2015 at 15:35
  • You could use a new format as /art-166/1-24463.html and then have a generic rule like RewriteRule ^art-(\d+)/(\d)-(\d+)\.html$ /art/details.php?articleid=$3&parentid=$2&catid=$1 [L] Commented Apr 21, 2015 at 15:41
  • What is your mean from 'new format'? Commented Apr 21, 2015 at 15:44
  • Well this is an example like yours: mydomain/art/24463.html. By new format i mean the new accessible url Commented Apr 21, 2015 at 15:45

2 Answers 2

1

Instead of mydomain/art/24463.html you should choose something like mydomain/art-166/1-24463.html.

This way, you'll include also parentid and catid which are dynamic parameters (and so, needed for rewriting).

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/art/details\.php\?articleid=(\d+)&parentid=(\d+)&catid=(\d+)\s [NC]
RewriteRule ^ /art-%3/%2-%1.html? [R=301,L]

RewriteRule ^art-(\d+)/(\d+)-(\d+)\.html$ /art/details.php?articleid=$3&parentid=$2&catid=$1 [L]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Justin,it works well and great,would you please let me know that the static format is prefer to daynamic specially from view of search engine?
Static is mainly better for users right now. You can find a note about it: googlewebmastercentral.blogspot.com/2008/09/…
0

Try this in htaccess tester

RewriteEngine on
RewriteRule ^art/(\d+).html$ art/details.php?articleid=$1&parentid=1&catid=166 [nc]

2 Comments

The problem here is that you have dynamic parameters such as parentid and catid. They can't be defined as static in your rule
thanks,but please not that parenetid and catid change in different articles.

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.