How to rewrite URL for user profile in .htaccess - .htaccess

My user profile URL looks like this: http://mysite.com/profile.php?user=Rango and I want to make it like: http://mysite.com/Rango
Maybe somebody can help with an example? Thank you very much.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /profile.php?user=$1 [L,QSA]

Related

.htaccess rewrite URL for my website

maybe you can help me to rewrite my URL (i never worked with a .htacces-file).
Example:
I have a URL like this: http://localhost/index.php?s=example
How i can chance this URL like this: http://localhost/example ?
Maybe you can help me.
Thank you!
You can use the following in root/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?s=$1 [NC,L]
This script will allow you to access /index.php?s=foobar using the clean url /foobar

How to make clean urls with .htaccess

I have this profile page which will show your profile with the url
localhost:8080/profile?username=ImSchnebz
But the thing is I want it to look like this:
localhost:8080/profile/ImSchnebz
I have tried a lot of different answers, but most of them give me 404 not found or 500 internal server error, I know this isn't anything you guys could help me with, but I've asked this question before, and gotten no response, so please, if there is anyone out there, please help me! :)
Thanks
EDIT:
I have this code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /profile.php?username=$1 [L,QSA]
And it works perfectly with localhost:8080/ImSchnebz but I want it to be localhost:8080/profile/ImSchnebz
Try
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/profile/(.*)$ /profile?username=$1 [NC]
Based on the link #Lawrence gave.
Try this:
RewriteEngine on
RewriteBase /
RewriteRule ^profile/(.*)$ profile.php?username=$1 [L,QSA]

How to make 'www.site.com/contact.php' to be 'www.site.com/contact/' ?

Looking for some help with my .htaccess file and mod-rewrite.
I want to make my URLs more friendly.
I would like to take my URLS from:
www.site.com/contact.php
to:
www.site.com/contact/
Any help would be much appreciated?
As you've already mentioned, you need to add an entry to the htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^contact /contact.php
Or if you want to do this to all of your php pages then just modify it as following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Want to rewrite URL through HTACCESS

I'm sure this has been asked in other forms, but I can't for the likes of me get this thing working after googling/trying for hours.
I have a bunch of URLs like this:
www.yoursite.com/pic_box.php?pic=$
What I want is that all URLs will only be avaiable with clean URLs.
www.yoursite.com/your-title-here
Can any htaccess master help me with this?
In your .htaccess:
RewriteEngine on
RewriteRule ^picbox/(.*)$ /pic_box.php?pic=$1 [NC,L]
Will give you the ability to rename your url like that:
www.yoursite.com/picbox/your-pic-id
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /pic_box.php?pic=$1 [L]

How to re-write this URL in PHP using .htaccess?

I am working on one website.
On this website, porfile URL currently is like this:
http://eprofile.co/eprofile.php?user=degroundshaker
I want to rewrite this URL as:
http://eprofile.co/degroundshaker
This, is addon domain so its files are under a folder called "eprofile.co" in my cPanel and there is one .htaccess file.
So, i need solution and please let me know what rule i need to add and what should be the complete format in .htaccess
I m newbie in .htaccess.
Try this:
RewriteEngine On
RewriteRule ^([^/]*)$ /eprofile.php?user=$1 [L]
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /eprofile.php?user=$1 [L]
Then you need to change all of your profile links from looking like this:
http://eprofile.co/eprofile.php?user=degroundshaker
to looking like this:
http://eprofile.co/degroundshaker
EDIT:
Alternatively, you could do:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/eprofile.php
RewriteRule ^([^/]*)$ /eprofile.php?user=$1 [L]

Resources