0

I want to rewrite

www.domain.com/xyzdetails.php?id=91741

to

www.domain.com/rakesh-gupta

rakesh-gupta is saved as rakesh gupta in the table as field title for php id 91741.

I tried method using below url, but didn't work out.

http://zenverse.net/seo-friendly-urls-with-htaccess/

Thanks

chris85
  • 23,846
  • 7
  • 34
  • 51
  • What do you mean by `didn't work out`? Did it error? What code did you use? – chris85 Jun 26 '16 at 03:11
  • https://github.com/phanan/htaccess – rjdown Jun 26 '16 at 03:21
  • Possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Oscar Barrett Jun 26 '16 at 06:26
  • I think you are trying to make your URL too friendly. If I'm not mistaken, you will have to hard code every single row of your table as a rewrite rule because the rewrite engine doesn't know in advance the `title` for a specific `id` and has no means of accessing it unless hard coding. Normally you would settle with rewriting `www.domain.com/details/91741` to something like `www.domain.com/xyzdetails.php?id=91741`. Sure that is not what you want ? – cachique Jun 28 '16 at 22:03

1 Answers1

1

If you want to rewrite by any static string like rakesh-gupta/12345 then the rule can be

# www.domain.com/rakesh-gupta/12345
RewriteRule ^rakesh-gupta/(\d+)$ 

And if you think your rewrite URL will be dynamic instead then the regex can be written as ^(.*)/(\d+)$. Here first group (.*) is anything (title, name, business, .....) and second group \d+ is for id and the rule is

# www.domain.com/rakesh-gupta/12345
# www.domain.com/title/12345
# www.domain.com/...../12345
RewriteRule ^(.*)/(\d+)$ /xyzdetails.php?id=$2

Hope it will make you sense.

MH2K9
  • 11,951
  • 7
  • 32
  • 49
  • Hi, Got a Q, rakesh gupta is just one value, so for entire table do i need to create htaccess file as RewriteEngine on RewriteRule ^title/(\d+)$ /xyzdetails.php?id=$1 – Rakesh Gupta Jun 26 '16 at 03:24
  • `RewriteRule ^(.*)/(\d+)$ /xyzdetails.php?id=$2`. it will work for any pattern `/any_char/id_no` – MH2K9 Jun 26 '16 at 03:33
  • my URL is http://rejoicep.com/recruitment-drive-detail.php?recrid=1 and I want this to convert with: http://rejoicep.com/Jobs-In-Andhra-Pradesh-For-ABAP-Consultant and like this to change with every id http://rejoicep.com/recruitment-drive-detail.php?recrid=2 http://rejoicep.com/Jobs-In-Adilabad-For-ABAP-Consultant I tried the below htaccess files. Option 1 RewriteEngine on RewriteRule ^(.*)/(\d+)$ /recruitment-drive-detail.php?id=$2 Option 2 RewriteEngine on RewriteRule ^jobtitle/(\d+)$ /recruitment-drive-detail.php?id=$1 Am I making some mistake here. – Rakesh Gupta Jun 26 '16 at 04:16