0

I am having a problem here, does anybody know How to change my url from

http://localhost/myProfile.php?id=1

to

http://localhost/myProfile/1
yllzon
  • 41
  • 1
  • 7

2 Answers2

1

Try this:

Options +FollowSymlinks
RewriteEngine on
AddDefaultCharset UTF-8 

RewriteCond %{REQUEST_URI} myProfile\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ [NC]
RewriteRule ^(.*)$ /myProfile/%1 [NC,L]

Note: The [0-9]+ is a regex for accepting numbers between 0 and 9. The + means that there can be more than one of them. You can use another regex if you wish like [A-F0-9]{32} for example which accepts letters A-F, numbers 0-9 and there can be a total of 32 characters. You can tweek it to suit your needs. Keep in mind that if the conditions are not met the RewriteRule will not happen.

Ivan86
  • 5,597
  • 2
  • 11
  • 30
  • in fact sometimes it works but it doesnt get the css – yllzon Dec 23 '17 at 23:14
  • What `CSS`? For `CSS` problems use `` tag under the `` tag. Check google for `base HTML tag` it will restore all the `CSS` links and everything should work. – Ivan86 Dec 23 '17 at 23:17
  • @yllzon based on your example your `base` tag should look something like this: ``. Put that in your `HTML` document inside the `` section. If you have problems ping me. Also, if my answer worked for you mark it as accepted please. Thanks – Ivan86 Dec 23 '17 at 23:30
0

Try this

RewriteEngine On


RewriteRule ^([a-zA-Z0-9_-]+)$ myprofile.php?user=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ myprofile.php?user=$1
kelrob-dev
  • 53
  • 1
  • 7