htaccess url with usernames [duplicate] - .htaccess

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 8 years ago.
What i wanted to do is first hide all .php extensions in my URL secondly i wanted all users to have there pages with there usernames like www.domain.com/username
however i can easily do the first with this code in my .htaccess.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php
Now how can i do the second part as if somebody goes to this domain www.domain.com/username server will route to www.domain.com/username.php but it should go to URL like www.domain.com/profile.php?id=username.
How can i achieve this?

Something like this, however it will redirect everything after the / to profile.php, so you have to make rules for all other urls before this, if needed.
RewriteRule (.*) profile.php?id=$1

Related

URL .HTACCESS LINK SETTING [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 1 year ago.
I have a link
https://example.com/article.php?article_link=10-scientists-who-made-the-dropsy-vaccine
i want this link to have a url like
https://example.com/article/10-scientists-who-made-the-dropsy-vaccine
where the last part of the link i.e 10-scientists-who-made-the-dropsy-vaccine is dynamic and can be anything
How can i do this???
You can do this with your htaccess . Open your .htaccess file and put the following rule :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/(.+)$ /article.php?article_link=$1 [L,NC]

some issue on rewriting url using htaccess [duplicate]

This question already has answers here:
How can I create friendly URLs with .htaccess?
(8 answers)
Closed 8 years ago.
When user visit "https://www.example.com/api3/SGy7bT" url then i want to load "https://www.example.com/api3/webhook3_index2.php?random=SGy7bT" page. On the browser the url will not change and it will appear like top mentioned url.
My htaccess file is exist on "/api3" folder.
Try:
RewriteEngine On
RewriteBase /api3/
RewriteCond %{THE_REQUEST} /api3/webhook3_index2\.php\?random=([^&\ ]+)
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILEAME} !-f
RewriteCond %{REQUEST_FILEAME} !-d
RewriteRule ^(.*)$ webhook3_index2.php?random=$1 [L,QSA]

Remove Query string from website url [duplicate]

This question already has an answer here:
Using .Htaccess url redirection
(1 answer)
Closed 8 years ago.
i want to remove query string from my url using htaccess but i cant find any proper solutions
www.mysite.net/index.php?title=Category:Public_Companies&redirect=no&pagefrom=GET+UP
I Want
www.mysite.net/Category:Public_Companies/GET+UP
How can i do this. Any help will be appreciated.
The fast and easy way
.htaccess
RewriteEngine On
RewriteRule ^(.*)/(.*) index.php?title=$1&pagefrom=$2&redirect=no [L]
I create for all characters you need define what character you will be use.
Php file for test .htaccess frendly url
<?php print_r($_GET); ?>
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?title=([^\s&]+)&redirect=no&pagefrom=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,NE,L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /index.php?title=$1&redirect=no&pagefrom=$2 [L,QSA]

convert dynamic URL into static URL with random id [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I want convert my URL with htaccess file
FROM
http://example.com/sfdf121d
TO
http://example.com/test.php?id=sfdf121d
Where 'sfdf121d' is a random no ,its changable
and my htaccess code is
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([0-9]+) test.php?id=$1 [L]
Here is an option. Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*/(\w+)$ [NC]
RewriteRule .* test.php?id=%1 [L]
Try:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ test.php?id=$1 [L]
You should provide more infos:
- which URL is the result when it returns 404
- is the 404 handled by a framework/cms
- what other conditions and rewrites exist there
I assume that the rewrite rule doesn't start with a number therefore it won't rewrite
Try checking from end.
RewriteRule ([0-9]+)$ test.php?id=$1 [L]
At any rate you should also check that you're not having test.php matched. So add before the above line following.
RewriteRule (.)?test.php(.)? - [L]
This can sure be also optimized :)

Htaccess redirect [duplicate]

This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
How to rewrite to mobile.myUrl.com if user is mobile? (use Apache or inside Webapp?)
Hi there! I'm trying to write a rewrite rule, that would redirect every address in my domain, to index.php, like this:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php
The problem with this code is that in index.php I check whether user came to my website from a pc, or a mobile device, and according to that I redirect him to appropriate version (index.html, or mobi.html) - now since this rule applies I'm stuck in a redirection loop. Pls help stackoverflowers :).
Either you just exclude the pages index.html and mobi.html:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/index.html
RewriteCond %{REQUEST_URI} !=/mobi.html
RewriteRule .* /index.php
or you can set a GET variable in your redirected url, like header('Location: domain.com/index.html?norewrite'); and then do not rewrite the URL if it contains this variable:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{QUERY_STRING} !^(.*&)?norewrite(&.*)?$
RewriteRule .* /index.php

Resources