2

My URL is: http://www.website.com/profile.php?username=xyz

But I want to change into this: http://www.website.com/xyz

Will it be possible using .htaccess?

I have tried but it gives me:

Internal Error.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteCond %{REQUEST_FILENAME} ! -d
RewriteRule (.*) profile.php?username=$1
Adas
  • 309
  • 1
  • 16
  • Can you show your rule (even if it is not working) – anubhava Sep 17 '15 at 07:18
  • RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} ! -f RewriteCond %{REQUEST_FILENAME} ! -d RewriteRule (.*) profile.php?username=$1 – Adas Sep 17 '15 at 07:22
  • 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) – Vidya Sagar Sep 17 '15 at 07:31
  • This code looks fine. Can you check your Apache error.log to see what is exact error when you get 500 (internal server error). – anubhava Sep 17 '15 at 07:31
  • [Thu Sep 17 13:07:15.016904 2015] [core:alert] [pid 2944:tid 840] [client ::1:59761] D:/wamp/www/website/.htaccess: RewriteCond: bad flag delimiters, referer: http://localhost/website/profile.php?username=xyz – Adas Sep 17 '15 at 07:40

1 Answers1

1

Try this code:

DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) profile.php?username=$1 [L,QSA]

There shouldn't be a space between ! and -f or -d in RewriteCond.

anubhava
  • 664,788
  • 59
  • 469
  • 547
  • Hi thank you for the reply, it is working But with any of the url is now page is opening. http://www.website.com/xyz, http://www.website.com/123abc....i think this is how it can be accomplish ? – Adas Sep 18 '15 at 12:01
  • Yes that's right. It will route any thing like `http://www.website.com/foobar` to `http://www.website.com/profile.php?username=foobar` Only your code inside `profile.php` can figure out whether username is valid or not by probably querying database. – anubhava Sep 18 '15 at 13:38
  • 1
    Yes it solved my query, you provided excellent help to me. thank you. – Adas Sep 18 '15 at 14:21