-1

I need to make my websites link user friendly. Currently, they look like this:

mydomain.com/post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26

I want to make them look like this:

mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html

I've written the following code into my .htaccess file:

    Options +FollowSymLinks
    RewriteEngine on    

    RewriteRule ^title/([^/]*)\.html$ /post.php?title=$1 [L]

I don't know why, but it doesn't work. How can I get it to work?

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • There are alot of questions about this topic on SO, you should also check Google... – Bun Feb 07 '14 at 16:55
  • What is not working? What is location of this .htaccess? Is .htaccess even enabled? – anubhava Feb 07 '14 at 16:56
  • What you asked is impossible regarding on your example because **News-Feeds-Latest-Addition-Puts-facebook-news-26** is not equal to **get-back-your-recycle-bin-IT-news-85** – Justin Iurman Feb 07 '14 at 16:56
  • @JustinIurman - The format is what matters in this case, not the content. – Chris Forrence Feb 07 '14 at 17:00
  • And @user3284742, I'd look at [this question](http://stackoverflow.com/q/3033407/899126); it should help get you on your way. – Chris Forrence Feb 07 '14 at 17:01
  • @ChrisForrence Not at all. You can't have a generic rule and have a logic link between two different params. If OP reaches `mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html` he will get content of `mydomain.com/post.php?title=get-back-your-recycle-bin-IT-news-85` ... not of `mydomain.com/post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26` – Justin Iurman Feb 07 '14 at 17:02
  • @JustinIurman - I'd agree with that, but what I think happened was he just got the example of what he wants from a different site and didn't adjust it to match his current state; that's all. – Chris Forrence Feb 07 '14 at 17:05
  • @anubhava I don't Know I m newbie in php. Location of .htaccess is in site root.I just tested .php files to be showed with .html and it works but when I try to rewrite that post.php query string it didn't work..... – user3284742 Feb 07 '14 at 17:43
  • @justinlurman i have two posts on index one with normal url structure and other with the url structure i want to apply that's why both title values are not same. – user3284742 Feb 07 '14 at 17:46

2 Answers2

0

You can use this code

Options +FollowSymLinks
RewriteEngine on

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

RewriteRule ^(title)/([^.]+)\.html$ /post.php?$1=$2 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • For which URL it is not working? What is location of this .htaccess? Is it website root OR in a sub-directory? – anubhava Feb 08 '14 at 07:11
  • it is a sub directory of on localhost and its not working for localhost/title/get-back-your-recycle-bin-IT-news-85.html and the .htaccess is in my project root folder in htDocs – user3284742 Feb 08 '14 at 09:38
  • Just tested it again and worked for `localhost/title/get-back-your-recycle-bin-IT-news-85.html` Are you sure .htaccess enabled? Verify whether your `.htaccess` is enabled or not, by putting same garbage (random) text on top of your `.htaccess` and see if it generates 500 (internal server) error or not? – anubhava Feb 08 '14 at 09:42
0

Use this :

RewriteEngine on

RewriteRule ^title/get-back-your-recycle-bin-IT-news-85.html/?$ post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26 [NC]

now you can usethis url : mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html