Forum Moderators: phranque
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]
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]
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
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
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
[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