%{ENV:UNIQUE_ID}

Discuss practical ways rearrange URLs using mod_rewrite.

%{ENV:UNIQUE_ID}

Postby nizzy » Thu Sep 25, 2008 7:39 am

Options +FollowSymlinks
RewriteEngine On
RewriteBase /tester

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/tester/(.*)/$ index.php?sid=%{ENV:UNIQUE_ID}

RewriteRule ^(.*)$ %{ENV:UNIQUE_ID}/ [R,L]

I have a directory called tester: http://site.com/tester/

.htaccess and index.php are located under this directory.

I like to redirect users to this pattern: http://site.com/tester/SNu4jlKl9IMAAGeA59w/

but I don't wanna show index.php (this is MVC file.)

how can i do that?

thank you in advanced

nizzy
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am

Postby richardk » Thu Sep 25, 2008 2:16 pm

What are you trying to achieve?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule [^/]$ /tester/%{ENV:UNIQUE_ID}/ [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^tester/[^/]+/$ ./index.php?sid=%{ENV:UNIQUE_ID} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

unique id missing in the url

Postby nizzy » Thu Sep 25, 2008 5:00 pm

Richard, thanks for quick reply

You code works fine, however, it does not redirect to a new url that has unique id in.

it does this now:
site.com/tester/ -> goes to -> site.com/tester/ with index.php outputs

I want to do this:
site.com/tester/ -> goes to -> site.com/tester/SNj3id8f75kfdeit34u/ <- here i want index.php outputs

thank you
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am

this is interesting

Postby nizzy » Fri Sep 26, 2008 7:04 am

Richard,

I wanted to implement this idea for Japanese mobile pages. We want a unique URL for each request. By using this url decoration, we can have this id as a cookie through out the visits.

thx
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am

Postby richardk » Tue Sep 30, 2008 2:39 am

Why do you need the UNIQUE_ID in the URL? It will exist in %{ENV:UNIQUE_ID}.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^tester(/(index\.php)?)?$ /tester/%{ENV:UNIQUE_ID}/? [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^tester/[^/]+/$ ./index.php?sid=%{ENV:UNIQUE_ID} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

didn't work either :-)

Postby nizzy » Tue Sep 30, 2008 6:43 am

Richard, I appreciate your help.

Bu this doesn't redirect either.

Let me explain why I need this. Some Japanese mobile phones don't allow you to set and preserve session variables throughout the visits. This is very unique issue still exist in DoCoMo phones. Basically, DoCoMo overrides all kinds of browser headers and send only limited header data. With this limited data, I think, server is not able to keep the session for that user.

For example, I am able to set some vars in the index.php, then as soon as you click a link and go to next page, all those vars disappear and session is restarted. Do you see my problem? this is very real issue. However, there is a hack around and I fixed it using the following code in my session class.

in .htaccess file:

php_flag session.use_trans_sid on

-or- in PHP:

ini_set('session.use_trans_sid', true);


in this case, PHPSESSID appears on the URL's. This is a big security (session fixation) matter.

Last solution is the idea I posted on this page. If I can keep a unique id in the url, then I can create my own session and map both.

Basically, I will do URL decoration, kind of cookie in the URL.

I believe it will work.

Thanks
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am

Postby richardk » Wed Oct 01, 2008 11:02 am

It will have the same security problems as the PHP session id in the query string. Also, if you can't track sessions Apache is highly unlikely to be able to track sessions so UNIQUE_ID will change for every request.

Bu this doesn't redirect either.

Where are you putting the mod_rewrite?
What URL are you going to?
Which URLs should be redirected?
Which URLs should not be redirected?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

here is how it should work

Postby nizzy » Wed Oct 01, 2008 6:30 pm

typical a user trail

step 1. http://www.site.com (we check whether browser is mobile or not, if mobile, php makes the redirect -> step 2)
step 2. http://www.site.com/m/ (.htaccess is here. we generate a unique_id for this user and redirects -> step 3)
step 3. http://www.site.com/m/SN67Hgde54kd83jhdk3/ (this is final destination and we are still under "m". And index.php is called here by htaccess, but not display in the URL)

dir "m" is for mobile has index.php and .htaccess files only.
SN67Hgde54kd83jhdk3 is unique_id and this directory does not exist, but I will capture this from index.php

Also, you said unique id will be RE-generated, true, but I don't care..bcos I captured one at the beginning and will use that in the url throughout the visit for that user. Now, how I will utilize this id is that I will store it in a flat file or DB. I will use this as a lookup table. Then I will create my own session file and vars. I will store them into the flat file or DB corresponding to that unique id in the URL. Remember, this unique id stay in the url during visits. So, I am able to identify that user from that URL. Otherwise, as I explained previously, DoCoMo mobile carrier is really overriding all proxy server headers, therefore my server is not able to create stable session id. This is a known issue by any developer in Japan. Everyone has his own solution. I think my solutions will work if I can fix the .htaccess redirect issue.
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am

Postby richardk » Thu Oct 02, 2008 3:48 am

Ok, try the following in a .htaccess file in /m
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule !^(([A-Za-z0-9@-]+)/?|index\.php)$ /m/%{ENV:UNIQUE_ID} [R,L]
RewriteRule ^([A-Za-z0-9@-]+)/?$ ./index.php?sid=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

perfect

Postby nizzy » Thu Oct 02, 2008 6:30 am

Richard, it works perfectly...like it

THANK YOU!!!
nizzy
 
Posts: 6
Joined: Thu Sep 25, 2008 7:33 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron