0

I was about to convert my webpage url into seo friendly. My url link is like follows

http://example.com/display.php?id=***

Now i want to convert this into seo friendly url, which could be

http://example.com/partners-id-***.html

Something like above. I used

RewriteEngine On
RewriteRule ^partners-id-([^-]*)\.html$ /display.php?id=$1 [L]

Rewrite rule in htaccess file. But still the url stays same as older one. Anyone can help me to fix this issue???

Chotu ManiKandan
  • 37
  • 1
  • 1
  • 7
  • rewrite_mod won't change your url magically. you need to change your url's to fit that format and url_rewrite will "rewrite" them so your php can understand the parameters. so change your url's to something like `partners-id-5.html` and in your display.php `echo $_GET['id']` will print 5 – Volkan Ulukut Feb 05 '14 at 12:55
  • It does **not** replace your html links. You have to do it manually. Anyway, if you try to reach `partners-id-5555.html` you should have the same content as `display.php?id=5555` – Justin Iurman Feb 05 '14 at 12:56
  • What can i do now to fix this one??? Any suggestions??? – Chotu ManiKandan Feb 05 '14 at 12:57
  • possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – deceze Feb 05 '14 at 12:57
  • there is nothing to fix, you got it wrong. read my comment. – Volkan Ulukut Feb 05 '14 at 12:58

2 Answers2

1

You need 1 more 301 rule before this rule for external redirection:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+display\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /partners-id-%1.html? [R=301,L]

RewriteRule ^partners-id-([^.]*)\.html$ /display.php?id=$1 [L,QSA]

As commented by Justin and other folks it is better to change your links to /partners-id-123.html. However for links already cached by search engines will be taken care by first rule here which will 301 redirect:

/display.php?id=1234 => /partners-id-1234.html
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • +1. Anyway, OP seems confused about html links. You should add he has to change links manually (see my comment) – Justin Iurman Feb 05 '14 at 13:01
  • -1 That's really not a good solution, it's a *lazy* solution. Having every single request cause a redirect is pretty bad. – deceze Feb 05 '14 at 13:02
  • Ya sure, see my comments in answer above. – anubhava Feb 05 '14 at 13:04
  • @deceze: This is *must to have* solution for the `/display.php?id=nnn` type links already cached in search engines. – anubhava Feb 05 '14 at 13:05
  • With the added comment it's alright now (you added it later, right? If I overlooked it initially, sorry). Just the first paragraph by itself was not. – deceze Feb 05 '14 at 13:06
  • @ChotuManiKandanL Which URL is causing 404? What do you see in browser and what it should be? – anubhava Feb 05 '14 at 13:08
  • Am getting url as http://example.com/partners-id-1234.html. but it shows 404 error.. – Chotu ManiKandan Feb 05 '14 at 13:14
  • 2nd rule is your existing rule which would internally rewrite above to `http://domain.com/display.php?id=1234` Do you have `display.php` in some sub directory? – anubhava Feb 05 '14 at 13:18
  • No where mentioned in your question and you write URL is `http://example.com/display.php?id=***` What is the sub directory name? Does that sub directory also have a .htaccess? – anubhava Feb 05 '14 at 13:42
  • How can you be helped if you don't answer my comments and give incomplete info in question. Read my previous comment again and answer all questions. I specifically asked what is the sub directory name where `display.php` is located? – anubhava Feb 05 '14 at 14:26
  • Those type of comments wont take this any where. Have tried my best to help you but it seems you don't even know your own setup. Comment first 2 lines of 301 rule and try to open `http://example.com/display.php?id=1234` and tell me what you see – anubhava Feb 05 '14 at 14:42
-1

Please try like below:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /display.php?id=$1 [L]
Pratik
  • 810
  • 6
  • 26