Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Javascript based url-rewrite  (Read 8808 times)

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
Javascript based url-rewrite
« Reply #1 on: February 12, 2007, 05:53:39 pm »

Or.... just get a new host and save yourself the trouble.  :rolleyes:

sNews works best if it's used as it was intended. Otherwise, your looking at modifying a RIDICULOUS amount of links.

tempeleng

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Javascript based url-rewrite
« Reply #2 on: February 13, 2007, 02:10:18 am »

Thanks mike but unfortunately we've already paid for the hosting. And some of my friends already have their own hobby projects online. I was thinking along the lines of:
Code: [Select]
var rwHostAddr = "";
var rwCurAddr = "";
rwHostAddr = "http://localhost/";
function urlrewrite(){
var rwElems = document.getElementsByTagName("a");
for ( var rwI = 0; rwI < rwElems.length; rwI++ ) {
rwCurAddr = rwElems[rwI].href;
if (rwCurAddr != rwHostAddr){
if (rwCurAddr.indexOf(rwHostAddr) != -1){
rwElems[rwI].href = rwHostAddr + decode(rwCurAddr);
}}
}
}
function decode(sUrl){
sUrl = sUrl.replace(rwHostAddr, "");
if (sUrl.charCodeAt(sUrl.length - 1) == 47)
sUrl = sUrl.substr(0, sUrl.length - 1);
var sOut;
if (sUrl.indexOf("/") == -1){
sOut = "index.php?category=" + sUrl;
} else {
var asQueries = sUrl.split("/");
for ( var rwI = 0; rwI < asQueries.length; rwI++ ) {
if (rwI == 0) { sOut = "index.php?category=" + asQueries[0]; }
if (rwI == 1) { sOut = sOut + "&title=" + asQueries[1]; }
if (rwI == 2) { sOut = sOut + "&commentspage=" + asQueries[2]; }
}
}
return sOut
}
/*
RewriteCond %{REQUEST_FILENAME} -f <-- regular file
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} -d <-- directory
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d  <-- not directory
RewriteRule ^(.*)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d  <-- not directory
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d  <-- not directory
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&commentspage=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d  <-- not directory
RewriteRule ^([a-z0-9_-]+)/([0-9]+)/ index.php?category=$1 articlespage=$2 [L]
*/
As you can see, the code is terrible. And I still can't understand the reg-exp in .htaccess. What I need to know is will it break sNews?
Logged