htaccess url rewrite for userprofiles - php

Every signed up member has an userprofile. The URL looks like: http://domain.com/content/profile/profile.php?username=USERNAMEOFTHEUSER
How do I rewrite it so it shows the URL as: http://domain.com/USERNAMEOFTHEUSER ?
I've tried:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^/]*)\.html$ content/profile/$1 [L,QSA]
But it aint working and I have no htaccess knowledge.
EDIT #1
Also, my map structure looks like this:
content/example1/example_file1.php
content/example2/example_file2.php
content/example3/example_file3.php
How do I hide the content/examples/ maps? So that: domain.com/content/example2/example_file2.php
turns into domain.com/example_file2 ?
Thanks!

This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /content/profile/profile\.php\?username=(.*)\ HTTP
RewriteRule ^ /%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /content/profile/profile.php?username=$1 [L]

Related

how to hide id from the url and make it clean url my directory of .htaccess file is /home/evidhya/public_html/tutorials/.htaccess

I have following url i would like to hide id and make it clean url
https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction
clean url should be like below url
https://www.evidhya.com/tutorials/AJAX/Introduction
I'm able to achieve using below htaccess code.
https://www.evidhya.com/tutorials/569/AJAX/Introduction
but i don't want 569 id in url
RewriteEngine On
#RewriteBase /KSTA-Webinar/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^(\d+)/?$ tutorials.php?qid=$1/$2/$1/$3 [L,QSA]
RewriteRule ^([\w.-]+)/?$ get_data.php?qid=$1 [L,QSA]
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^tutorials\.php$ /%1/%2/%4? [R=301]
RewriteRule ^tutorials/([\w+%]{2,50})$ /tutorials.php?qid=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ tutorials.php?qid=$1&user=$2&date=$3
RewriteRule ^([^/]+)/([^/]+)/(.+)$ tutorials.php?qid=$1/$2/$1/$3 [L]
Well, it seems the id is needed to determine the resulting url.
I would do this:
RewriteEngine on
RewriteRule (\d+)/(\w+)/(\w+) tutorials.php?qid=$1/$2/$3 [L]
and place this rule in tutorials/.htaccess.
And when someone goes to https://www.evidhya.com/tutorials/569/AJAX/Introduction it should load https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction

.htaccess url rewrite to room/Blabla

I got a question, I'm trying to edit my url using htaccess and its somehow broken...
My url: url.com/room.php?videoID=Blabla
The url I want: url.com/room/Blabla
I wrote something which actually worked, but considered file.php as a videoID and returned error.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^es/([a-zA-Z0-9-]+)$ room.php?roomID=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)$ room.php?roomID=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Use this in your .htaccess:
RewriteEngine On
RewriteRule ^room/([^/]*)$ /room.php?videoID=$1 [L]
It will give you the following URL: url.com/room/Blabla

How to rename part of a url with .htaccess?

I currently have very little Apache experience, and am having difficulties with my .htaccess file. My question is this: how can I rename these files, listed below, properly? I believe my syntax is accurate, according to http://www.htaccesscheck.com, but when accessing these pages, either A: the page won't load due to a redirect loop, or B: the page won't load, but will redirect to the wrong page. Here is my current .htaccess file for this directory:
RewriteEngine On
RewriteBase /photos/
RewriteRule ^(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
RewriteRule ^(.*)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
Any help is much appreciated.
Try code below:
RewriteEngine on
RewriteBase /photos/
RewriteRule ^([0-9]{1,2})-([0-9]{4})$ archives.php?month=$1&year=$2 [L]
RewriteRule ^([0-9]+)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
This rules will check, if:
request like yourdomain/11-1111, then return archives.php
request like yourdomain/111, then return catpost.php (you can type
any number)
else will return viewpost
You have some errors in your current .htaccess, because your second rule get result of first rule.
By the way, you can use http://htaccess.madewithlove.be/ to check step by step what is posted to your rewrite rules.
be sure to write a valid pattern
try this
RewriteEngine On
RewriteBase /photos/
RewriteRule ^(.*?)-(.*?)$ archives.php?month=$1&year=$2 [L]
RewriteRule ^(.*?)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*?)$ viewpost.php?id=$1 [QSA,L]

Using htaccess to rewrite url with variables?

Using htaccess how can instead of the following to have something like
http://domain.com/verify
or
http://domain.com/verify?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_
Here is the original
http://domain.com/account/index.php?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_
My current htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^login$ account/index.php [NC]
RewriteRule ^register$ account/index.php?register [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Try this RewriteRule with the regex pattern
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^varify/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$/account/index.php?foo=$1&bar=$2 [NC,QSA,L]
change the variables foo and bar with your variables.
All requests to example.com/varify/var1/var2 will be redirected to example.com/account/index.php?foo=$1&bar=$2

htaccess: different url for same page doesn't work

I've got these lines in htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [NC]
RewriteRule ^(.*)/(.*)$ index.php?page=$1&article=$2 [NC]
when it comes to address like this /news/test, page variable would be like index.php.
any idea how to fix that?
You have (.*) matching in first row which will match for both your scenarios.
Try this out it worked for me in following scenarios:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /index.php?page=$1&article=$2 [L]
RewriteRule ^(.*)$ /index.php?page=$1 [L]
It worked for:
http://www.example.com/news/test -> http://www.example.com/index.php?page=news&article=test
http://www.example.com/news/ -> http://www.example.com/index.php?page=news&article=
http://www.example.com/news -> http://www.example.com/index.php?page=news
Let me know, if you need to do something else. To test it properly i have added [L,R=302] instead of [L] to see if URL is forming correct or not.

Categories