1

Hello here is what I am trying to do : if someone goes to site.com/myusername they get sent to site.com/index.php?a=profile&u=myusername

should be pretty simple if you know htaccess rewrite engine. also any good beginner tutorials for something similar ?

here is my present .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{request_filename} -f [OR]
RewriteCond %{request_filename} -d
RewriteRule ^ - [L]

RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ /index.php?a=$1&q=$3 [L,QSA]

RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]
4
  • stackoverflow.com/questions/3086325/… Commented Jul 16, 2013 at 7:34
  • 1
    stackoverflow.com/questions/16388959/url-rewriting-with-php you should try searching for existing posts.. Commented Jul 16, 2013 at 7:37
  • Loads of other posts here and elsewhere about how to rewrite urls. Try learning to use search tools and you will find development so much easier Commented Jul 16, 2013 at 7:38
  • thank you guys im checking those links Commented Jul 16, 2013 at 8:13

3 Answers 3

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

4 Comments

hello anubhava. there is already a : RewriteCond %{request_filename} -f RewriteRule ^(.*) $1 [L] RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L] at the top that is being used. can you edit the code please? because when i added yours underneath it didnt work
Looks like you got it working. If you're still facing issues, pls provide your current .htaccess in your question (not in comments).
check please. I added it
I edited your .htaccess in your question with my suggested changes.
1

If the url is as specified , you can do something like

if (!isset($_REQUEST['u'])) {

$x = $_SERVER['REQUEST_URI'];
$y = str_replace('?', '', $x);
$z = str_replace('/', '', $y);
header("Location: ?a=profile&u=$z"); }

Not really a good solution though, but this was what I could think of..if you want to do it in php..

Comments

0

I know you already got the answer. But i just figured it before one hour. But my system problem so only i am posting it later. This is also one way to do.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /  
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?a=profile&q=$1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.