FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


.htaccess rewrite





Asap170
Alright so I want to write some of my urls

Example:

http://www.mysite.com/users/test

http://www.mysite.com/index.php?user=test

But where the user is (In this case "test"). It will be a variable to get session data and see the user's username.

Any help would be greatly appreciated.
hiwaypilot
I'm not sure at what point you want to use this... post login... link from page... etc. but there are a couple of ways to do it.

Easiest would be to set a session variable with your login...

$_SESSION['test'] = $username;

That variable would remain until the user logged out or session timed out.

The other common way would simply to use cookies.
Asap170
I am using session and that I have no issues, but idk how to access my session from the .htaccess file
jmraker
.htaccess is an apache web server configuration file, there should be no way for it to parse and access the data in a session file that is created by php.

Code:
RewriteEngine On
RewriteRule ^user/(.*)$ index.php?user=$1 [L]


With this in your .htaccess file whenever someone visits
http://yoursite.com/user/asdf
it will call the /index.php script as if they entered http://yoursite.com/index.php?user=asdf to get to the page

If you want to print the link to the page you'd use
Code:
echo '<a href="http://yoursite.com/user/' . $_SESSION['username'] . '">My profile</a>';
Asap170
jmraker wrote:
.htaccess is an apache web server configuration file, there should be no way for it to parse and access the data in a session file that is created by php.

Code:
RewriteEngine On
RewriteRule ^user/(.*)$ index.php?user=$1 [L]


With this in your .htaccess file whenever someone visits
http://yoursite.com/user/asdf
it will call the /index.php script as if they entered http://yoursite.com/index.php?user=asdf to get to the page

If you want to print the link to the page you'd use
Code:
echo '<a href="http://yoursite.com/user/' . $_SESSION['username'] . '">My profile</a>';


This sounds promising! I sure hope it works! I am gonna try it out now.

Well I have tried it and it doesn't work. I don't know why. I went and tested my .htaccess file and it is working, but that above isn't working...
ogah
how can make file html will processed as php file?

in my old site i use
AddType application/x-httpd-php .html

but in my new site not work
all html file not open at browser, but downladed same like we download a content from site.
i already try each below
AddType application/x-httpd-php5 .html
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php5 .html

still not work
Asap170
ogah wrote:
how can make file html will processed as php file?

in my old site i use
AddType application/x-httpd-php .html

but in my new site not work
all html file not open at browser, but downladed same like we download a content from site.
i already try each below
AddType application/x-httpd-php5 .html
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php5 .html

still not work


Not that sure since I am not good with .htaccess stuff.
Peterssidan
I tested AddType application/x-httpd-php .html and that works for me here on frihost.
Fire Boar
For more flexibility, you could rewrite ALL incoming requests to index.php (or some other front script). By ALL I mean excluding files which exist already (you don't want to rewrite requests for images to index.php) and favicon.ico (which browsers will request automatically, assuming that it exists).

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


Then if someone requests http://example.com/some/page, $_GET['q'] == 'some/page'.
sonam
Like hiwaypilot wrote the easiest way is sessions. If you are using sessions why you need $_GET. Session is always available via session_start and you don't need to rewrite urls. $_GET is not session function.

Sonam
Asap170
I still can't figure out what what to do.

I have this in my .htaccess file.
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


I go to http://mywebsite.com/user/test

It doesn't change to http://mywebsite.com/index.php?=test
Peterssidan
It has been some time since I did any mod_rewrite but this rule doesn't look right
Quote:
Code:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

(.*) this will match any characters so if the user try to access mywebsite.com/user/test it will be translated to mywebsite.com/index.php?q=user/test. At least that what I think will happen. You can easily verify this by printing the value of $_GET['q']. I'm not sure about the QSA flag, have never used it myself.

Maybe this is more what you want?
Code:
RewriteRule ^user/(.*)$ index.php?q=$1 [L,QSA]

.. still not sure about the QSA flag though.
Asap170
Still doesn't work. I don't know why. Any ideas?
ogah
Peterssidan wrote:
I tested AddType application/x-httpd-php .html and that works for me here on frihost.

for other hosting, not frihost
akun
Easy, you can rename the file for one normal name, save new parameters and will save using the original name:

.htaccess -> user_acess.txt
save new parameters into user_acess.txt
user_acess.txt -> .htacess


Smile
Related topics
.htaccess instead of mod_rewrite
htaccess
Appache Mod Rewrite
php (phpBB) help
Please Please give me some understanding
Rewrite Rule in .htaccess
Frihost time. -Marketplace-
How do other sites do what I want to do?
Help needed with mod rewrite
.htaccess SEF urls
.htaccess Problem - PLEASE help - Reward Offered
rewrite rule htaccess
.htaccess rewrite not working - any suggestions
hide folder or files in url bar
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.