Siv
Siv

Reputation: 1066

htaccess 2 mod_rewrite

I am a beginner in .htaccess can any one help me with this?

//my .htaccess code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /alumini/profile.php?username=$1

//with the above i can redirct the url

localhost/alumini/profile.php?username=name

to

localhost/alumini/name

but i also want to hide loacalhost/alumini/index.php to loacalhost/alumini

in simple ....

i want an htaccess code to hide the index page also i need to convert

localhost/alumini/profile.php?username=name

to

localhost/alumini/name

Upvotes: 1

Views: 114

Answers (2)

mychalvlcek
mychalvlcek

Reputation: 4046

RewriteRule ^localhost/alumini/([a-zA-Z0-9]+)$ /alumini/profile.php?username=$1
RewriteRule ^localhost/alumini$ /alumini/index.php

Upvotes: 0

Maccath
Maccath

Reputation: 3966

Your first request is a rewrite, not a redirect. Your second is a redirect. For the re-write, the following rule should do the trick (untested):

RewriteRule ^localhost/alumini/([a-zA-Z]+)$ /alumini/profile.php?username=$1

The regular expression inside the brackets matches one or more upper or lowercase letters and nothing else, and the value of the match is passed to $1. You may need to change the regular expression depending on the format of your usernames.

and for the index.php redirect (to remove the index.php where it exists):

Redirect 301 /alumini/index.php http://localhost/alumini

The 301 represents the fact that the page has moved permanently, and is better for SEO as only the non index.php page will be indexed.

Upvotes: 2

Related Questions