0

I am having problem with htaccess in which I want to have the same method of index.php?p='$_GET['page']' to apply for my account.php?username='$_GET['username']' in the same website. This is my htaccess code:

RewriteEngine on
RewriteRule ^inc/.*$ index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?p=$1 [QSA,L]

RewriteEngine on
RewriteRule ^inc/.*$ index.php?p=account.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?p=account.php&username=$1 [QSA,L]

I want the url in my page to be similar or the same like this:

www.composeplus.com/page

and when user logged in and access to their account name it should be like this:

www.composeplus.com/username

or

www.composeplus.com/account/username

Does anyone have the solution for me? thanks

2
  • Basicly its on you what kind of URL you deliver, the only thing you need is bootstrap each route to index.php. So if the user is logged in, show only links with that start with www.composeplus.com/account/username Your .htaccess first part seems ok, second part is not needed. Commented Mar 13, 2017 at 11:59
  • But when I try www.composeplus.com/account/pagna (pagna is my username) it show: Not Found The requested URL /composeplus.com/account/pagna was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. When I use only the above code Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.5.38 Server at localhost Port 80 Commented Mar 13, 2017 at 12:06

1 Answer 1

0

Let me have a try that makes my comment a little clearer.

Creat an .htaccess in the root-web folder of your server like

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)$ index.php?qwerty=$1 [QSA,L]

So now everthing that is not a real file will be redirect to index.php with the full URL as qwerty=FOO/BAR

In index.php you can know react on the given input.

Lets say you call www.composeplus.com/account/username it will redirect to www.composeplus.com/index.php?qwertz=/account/username and www.composeplus.com/page to www.composeplus.com/index.php?qwertz=/page

That is basicly how redirect work. Normaly a function in index.php will check qwertz and call the needed subfiles/classes depending on your api.

NOTE: It is an example, your stuff has inc/ folder and i dont know for what that is.

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

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.