0

This is my non-friendly URL: localhost/website/users/?name=UserA

Now, i tried to create a friendly URL using .htaccess file.

This is everything in my .htaccess file:

ErrorDocument 404 /movies/error404.html  #For Error 404

RewriteEngine On
RewriteRule /website/users/(.*)$ /website/users/name=$1

Now, When I open localhost/website/users/UserA it opens error 404 page.

Yes mod_rewrite is enabled

Ravina Sharma
  • 51
  • 1
  • 8
  • `RewriteRule /website/users/(.*)$ /website/users/?name=$1` try this – Syed Aqeel Jun 08 '17 at 08:13
  • 1
    Possible duplicate of [How can I create friendly URLs with .htaccess?](https://stackoverflow.com/questions/3033407/how-can-i-create-friendly-urls-with-htaccess) – LF00 Jun 08 '17 at 08:14
  • Here is the complete guide you can learn it from here: https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained – Shahroze Nawaz Jun 08 '17 at 08:16
  • Not working @FahadKazmi bro – Ravina Sharma Jun 08 '17 at 08:22
  • If your non-friendly URL is working (I'm surprised) then either the rewrite rule needs to issue a redirect (put ` [R]` at the end of the rule), in which case the browser will still show the non-friendly URL after visiting the friendly one. Otherwise the second argument in the RewriteRule should be relative to the .htaccess file's location, and look more 'internal' e.g. `RewriteRule /website/users/(.*)$ website/users.php?name=$1` (I don't have enough information to give a 100% working example, I'm just explaining) – Lee Kowalkowski Jun 08 '17 at 08:27
  • `RewriteRule ^website/users/([0-9A-Za-z]+)/?$ website/users/index.php?id=$1 [NC,L] ` try this one – Syed Aqeel Jun 08 '17 at 08:28
  • Still not working @FahadKazmi http://prntscr.com/fhaw75 – Ravina Sharma Jun 08 '17 at 08:31
  • Still not working @FahadKazmi – Ravina Sharma Jun 08 '17 at 08:34
  • It is not working may be because of `ErrorDocument` – Syed Aqeel Jun 08 '17 at 08:35
  • I tried to remove Error Document, still not working bro – Ravina Sharma Jun 08 '17 at 08:37

1 Answers1

0

Try this in your .htaccess file

#Options +FollowSymlinks
RewriteEngine On
RewriteRule    ^users/([0-9A-Za-z]+)/?$    users/index.php?name=$1    [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ErrorDocument 404 http://localhost/movies/error404.html

In this cause the .htaccess file would be placed under the website directory root

Note: The requests are going to index.php file which is under the users directory if you have another filename then replace it with that one

Syed Aqeel
  • 1,009
  • 2
  • 13
  • 36