Sreng Pagna
Sreng Pagna

Reputation: 39

htaccess solving duplicate get variable

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

Upvotes: 0

Views: 54

Answers (1)

JustOnUnderMillions
JustOnUnderMillions

Reputation: 3795

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.

Upvotes: 0

Related Questions