3

Let website link is www.abc.com I have 3 PHP Files.

  1. index.php
  2. profile.php
  3. group.php

My Current URL is -

  1. abc.com/directory/index.php
  2. abc.com/directory/profile.php?name=piash
  3. abc.com/directory/group.php?name=CSE

I want to convert it to-

  1. abc.com/home
  2. abc.com/piash or abc.com/abrar (piash and abrar is GET parameter to profile.php file)
  3. abc.com/group/CSE (CSE is the GET parameter to group.php)

I am using RAW PHP.

Is it possible?

If possible, how and where to put the .htaccess file?

In the root (abc.com) or in the folder (abc.com/directory) ?

Can anyone help me please?

Thanks in advance.

5
  • 3
    Sure, it's definitely possible using an .htaccess file. You could also have all requests go to index.php and handle the request using routing. Have you made any attempts of your own yet? Commented Nov 3, 2014 at 3:39
  • But, how can I do it? What is the code? Commented Nov 3, 2014 at 3:46
  • No no, that's not how this works. Where is your code you've used to attempt this? Commented Nov 3, 2014 at 4:02
  • .htaccess file doesn't use php code. Take a look at this tutorial. Attempt it yourself, show us what you got if it doesn't work, then come back here, posting your .htaccess code. Commented Nov 3, 2014 at 4:11
  • 2
    P.S. I have done a similar thing with my site, so I do know the answer. But you need to at least try yourself, otherwise you will learn nothing. Commented Nov 3, 2014 at 4:14

1 Answer 1

1

You can use this code in your /directory/.htaccess file:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /directory/

RewriteRule ^home/?$ index.php [L,NC]

# ignore files/directories from further rules
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^group/([^/]+)/?$ group.php?name=$1 [L,QSA,NC]

RewriteRule ^([^/]+)/?$ profile.php?name=$1 [L,QSA]

References:

Sign up to request clarification or add additional context in comments.

1 Comment

But where to put the .htaccess file?

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.