Welcome to WebmasterWorld Guest from 54.145.223.197

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help: rewriterule for session id needed

mod_rewrite session handling

     
9:56 pm on Feb 28, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2003
posts:5
votes: 0


Hi!

For some of my projects I need a rewriterule to convert sessionids:

Old version:
============
Up to now my urls are like the following
---with cookies:---
www.domain.com/news/news.php4?newsid=123
If cookies are not activated the url gets changed by reload:
---without cookies:---
www.domain.com/news/news.php4?newsid=123&dclp=987654321

I would like to change my urls to get my websites indexed by google and friends:

Idea 1:
=======
---with cookies:---
www.domain.com/news/news_123.html
---without cookies:---
www.domain.com/sid/987654321/news/news_123.html
or
www.domain.com/sid987654321/news_news_123.html

Idea 2:
=======
---with cookies:---
www.domain.com/news/news_123
---without cookies:---
www.domain.com/news/news_123/sid/987654321
or
www.domain.com/news/news_123/sid987654321

How can I realize one of these ideas?

Which one is better to get indexed by google?

Iīve tried many rewriterules but no one worked.

I hope you can help me!

Best regards

Frank

[edited by: DaveAtIFG at 3:01 am (utc) on Mar. 1, 2003]
[edit reason] Deleted specific URLs [/edit]

10:00 pm on Feb 28, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2003
posts:10
votes: 0


If you put the session ID in the url like that you'll end up with duplicate pages. Every time googlebot visits it will get a different URL but the same page.

Duplicate page penalty will come into play.

10:14 pm on Feb 28, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Welcome to Webmaster World, Frank_O!

This should do what you want. Here is a good mod_rewrite resource [engelschall.com].

RewriteEngine On
RewriteRule ^/news/news\.php4?newsid=(.*)$ /news/news_$1
RewriteRule ^/news/news\.php4?newsid=(.*)&dclp=(.*)$ /news/news_$1/$2
[L]

10:34 pm on Feb 28, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2003
posts:5
votes: 0


Hi Birdman, hi all,

thanks, but thatīs not the solution:

My old Rewrite rule (doesnīt work):

RewriteRule ^(.*)/sid/(.*)/(.*)$ /$1/$3&sessionid=$2

The /sid/987654321 should be extracted and appended at the end as my sessionid.

When I enter the url:
www.domain.com/sid/987654321/somethingelse?a=1

The following url should be processed:
www.domain.com/somethingelse?a=1&sessionid=987654321

The problem is to get the sessionid from the front to the end.

How can I realize this?

Best regards

Frank

11:10 pm on Feb 28, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Sorry aboout that. I had it completely backwards. This looks right.
RewriteEngine On
RewriteRule ^/news/news_(.*)$ /news/news.php4?newsid=$1
RewriteRule ^/news/news_(.*)/(.*)$ /news/news.php4?newsid=$1&sid=$2[L]
12:44 am on Mar 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


shrewsbury_matt's timely warning still applies...

Jim

P.S. You'll probably have to escape those underscores, i.e., use \_

1:18 am on Mar 1, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2003
posts:5
votes: 0


Hi!

Here is my actual .htaccess for url rewriting.
Please check out the last line with "COMPLETE_TAIL".

---------------------------------

RewriteEngine on
Options +FollowSymlinks
RewriteBase /mountainbike

#News
RewriteRule ^news/news_(.*).html$ /news/news.php4?newsid=$1

#Forum
RewriteRule ^forum/frage_(.*).html$ /forum/frage.php4?nr=$1

#Kleinanzeigen
RewriteRule ^kleinanzeigen/kleinanzeige_(.*).html$ /kleinanzeigen/kleinanzeige.php4?nr=$1

#Veranstaltungen
RewriteRule ^veranstaltungen/veranstaltung_(.*).html$ /veranstaltungen/veranstaltung.php4?vid=$1

#Touren
RewriteRule ^touren/tour_(.*).html$ /touren/tour.php4?tourid=$1

#Links
RewriteRule ^verzeichnis/rubrik_(.*).html$ /verzeichnis/rubrik.php4?rubrik=$1

#Session-ID from front to back
#**************************************************
#RewriteRule ^sid/(.*)/(COMPLETE_TAIL)$ /$2&sessionid=$1
#**************************************************

---------------------------------

For adding the session id I need the last RewriteRule.

?
Whatīs the regular term for COMPLETE_TAIL (which often includes many subdirectories, parameters and "/" and "?" etc.)?
?

The leading "sid/<many_digits>" must be appended to the end as "&sessionid=<many_digits>".

Best regards

Frank

1:52 am on Mar 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Frank_OL,

#Session-ID from front to back
RewriteCond %{QUERY_STRING} (.*)
#RewriteRule ^sid/(.*)/(.*)$ /$2?%1&sessionid=$1

The "%1" back-references the query string matched in the preceding RewriteCond

HTH,
Jim

2:21 am on Mar 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2003
posts:5
votes: 0


Hi!

The session handling and the html-to-php-converter donīt work together.

My htaccess-file:

***********************************

RewriteEngine on
Options +FollowSymlinks
RewriteBase /mountainbike

#----------------------------------
#----- html-to-php4-converter -----

#News
#RewriteRule sid/(.*)/news/news_(.*).html$ /news/news.php4?newsid=$2&rule=20&dclp=$1
RewriteRule news/news_(.*).html$ /news/news.php4?newsid=$1&rule=1

#Forum
RewriteRule forum/frage_(.*).php$ /forum/frage.php4?nr=$1&rule=2

#Kleinanzeigen
RewriteRule kleinanzeigen/kleinanzeige_(.*).html$ /kleinanzeigen/kleinanzeige.php4?nr=$1&rule=4

#Veranstaltungen
RewriteRule veranstaltungen/veranstaltung_(.*).html$ /veranstaltungen/veranstaltung.php4?vid=$1&rule=5

#Touren
RewriteRule touren/tour_(.*).html$ /touren/tour.php4?tourid=$1&rule=6

#Links
RewriteRule verzeichnis/rubrik_(.*).html$ /verzeichnis/rubrik.php4?rubrik=$1&rule=7

#----- html-to-php4-converter -----
#----------------------------------

#----------------------------------
#Session-ID from front to back
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^sid/(.*)/(.*)/(.*)$ /$2/$3?%1&dclp=$1&rule=8 [L]
RewriteRule ^sid/(.*)/(.*)$ /$2?%1&dclp=$1&rule=9 [L]
RewriteRule ^sid/(.*)$ /?%1&dclp=$1&rule=10
#----------------------------------

*******************************

The problem:

my link to the news-site:
[mountainbike.de...]

the result after rewriting:
[mountainbike.de...]

The result hasnīt got the old session-id, because only rule 1 has been processed. (The dclp-tail in the resulting url hasnīt been set by the rewrite rules but by the redirect-function in my session-handling-class.)

A combined rule like rule20 (in my htaccess-file) doesnīt work.

Links to urls ending with a directory or .php4 work fine.

Where is the mistake in my htaccess-file?

Best regards

Frank

3:08 am on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Frank_OL,

You must repeat the RewriteCond for each RewriteRule. The RewriteCond only applies to the first RewriteRule which follows it.

Jim

1:14 pm on Mar 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 25, 2003
posts:5
votes: 0


Hi!

It doesnīt work.

How can I assess and especially define the order of rules processed while rewriting the url?

1:42 pm on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


The RewriteRule [httpd.apache.org]s are processed in the order they appear in your .htaccess file. RewriteCond [httpd.apache.org] rules are evaluated if their corresponding RewriteRule [httpd.apache.org] matched.

[L] (last) will stop the rewriting process when it is encountered. [N] (next) will restart the rewriting process at the beginning. [C] (chain) lets you chain RewriteRule [httpd.apache.org]s together. If the first rule in a chain does not matched all others in that chain will be skipped.

Andreas

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members