0

I want to make User Friendly Url for my website with .HTTACCESS

This default my URL

domain/?p=news-details&id=4

I Want to like this

domain/news-details/4

This is what I have so far, but it is not working:

RewriteEngine on
RewriteRule //(.*)$ /?p=news-details&id=$1

thanks for responded.

Novry
  • 23
  • 9
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Masivuye Cokile Feb 14 '18 at 09:41
  • 2
    Possible duplicate of [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – er.irfankhan11 Feb 14 '18 at 09:48

1 Answers1

0

If your ID is always an integer you can do something like this:

RewriteRule ^news-details/([0-9]+)$ phpPage.php?p=news-details&id=$1 [L]

Where ([0-9]+) is a pattern that matches a group of 1 or more numbers from 0 to 9.

[L] means if the rule matches, don't process any more RewriteRules below this one.

xyzale
  • 655
  • 8
  • 14
  • Thanks For responded xyzale still the same, no changes – Novry Feb 14 '18 at 09:41
  • If its not an integer? – Masivuye Cokile Feb 14 '18 at 09:41
  • 1
    If it's not an integer you need to apply a proper regex, like for example `([a-z0-9_-]+)` in order to allow lowercase letters numbers, dashes and underscores. – xyzale Feb 14 '18 at 09:43
  • @Novry check my latest changes, I added the php file meant to be executed. – xyzale Feb 14 '18 at 09:46
  • ok @xyzale I've implemented a new scritpt, but it still does not work, this script `RewriteRule ^news-details/([0-9]+)$ index.php?p=news-details&id=$1 [L]` – Novry Feb 14 '18 at 09:56
  • Check I wrote news-details rather than news-detail, your url wants to be singular but the get var is plural, I edited the answer now – xyzale Feb 14 '18 at 09:57
  • i'm sorry @xyzale, i mean news-details not news-detail, I have edited but still doesn't work – Novry Feb 14 '18 at 10:07
  • @Novry I have a doubt ... you wrote .HTTACCESS, be sure the file is .htaccess with one T – xyzale Feb 15 '18 at 10:52