21
jayjay
Re: URL changer
  • 2008/6/12 7:44

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


Quote:

frankblack wrote:
The file header.php inside modules / news (if there is any) should look like this (right before any other code):
if(strpos(getenv('REQUEST_URI'), '/modules/smartsection/') === 0)
{
$oldurl getenv('REQUEST_URI');
$newurl str_replace("modules/news""newmodulename"$oldurl); header("HTTP/1.1 301 Moved Permanently");
header("Location: $newurl");
}


Good luck!


I think you mean:

if(strpos(getenv('REQUEST_URI'), '/modules/news/') === 0)
{
$oldurl getenv('REQUEST_URI');
$newurl str_replace("modules/news""newmodulename"$oldurl); header("HTTP/1.1 301 Moved Permanently");
header("Location: $newurl");
}

22
jayjay
Re: URL changer - homepage redirect solution
  • 2008/6/12 9:11

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


Howdie! This is a very nice trick! Had no problems implementing it to all of my modules (so far ).

You may notice that you still get redirected to a '/modules/yourmodule' subfolder when you visit your homepage and have set a 'Module for your start page' in 'Config Panel' - 'General Settings'. This is because this redirect is hardcoded in XOOPS of course.

There is a very easy way to mask this behaviour with Apache mod_rewrite.

First add this to your root .htaccess file:
RewriteEngine on
RewriteCond 
%{REQUEST_URI} !^/.+/ 
RewriteRule ^$ /modules/yourmodule/ [L]


Change 'yourmodule' to whatever module you like (news, wfdownloads...)

Then change the setting 'Module for your start page' to 'None' in 'Config Panel' - 'General Settings'.

This way Apache mod_rewrite will take care of your start page redirect. This will of course only affect your base url, eg. http://www.domain.com/

Edit: Better still, also include root index.(php|html|htm) files

RewriteEngine on
RewriteCond 
%{REQUEST_URI} !^/.+/ 
RewriteRule ^(index(.php|.html|.htm))?$ /modules/yourmodule/ [L]

23
jayjay
Re: URL changer - string support for xoRewriteModule
  • 2008/6/13 13:38

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


Hi Dugris and everyone else!

Thanks for this great smarty output filter! I got it to work on my site in less than half an hour! Beautifully done . For now, this filter only rewrites module folders: 'modules/xigg' changes to 'news' etc.

I was wondering if it were possible to add support for string rewriting? All those funny string characters à la 'cid=0&smode=Weekly&action=View&event_id=7502&caldate=2008-6-13' are driving me crazy! I know it can be done with smarty output filters, but maybe someone can help a hand?

I see two ways to rewrite urls: specific rewrites per-module or global rewrites for selected modules.

For 'global' rewrites I especially like the work done with suin's simplified urls hack:
function simplify_urls($s
{
    
$XPS_URL str_replace('/','/'quotemeta(XOOPS_URL) );
    
$s absolutize($s); // Fix URLs and HTML.
    
    
$in = array(
        
// Search URLs of Xoops's root directry.
          
'/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '
/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '/<(a|meta)([^>]*)(href|url)=(['"
]{0,1})'.$XPS_URL.'/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        // Search URLs of modules' directry.
        
'/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '
/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '/<(a|meta)([^>]*)(href|url)=(['"
]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        
'/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '
/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '/<(a|meta)([^>]*)(href|url)=(['"
]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        
'/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
        , '
/<(a|meta)([^>]*)(href|url)=(['"]{0,1})'.$XPS_URL.'/modules/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).php?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)&?(?:amp;)?([a-zA-Z0-9_-]+)=([a-zA-Z0-9_-]*)(#?[a-zA-Z0-9]*)(['"]{1})([^>]*)>/i'
    );
    
    
$out = array(
        // Replace URLs of Xoops's root directry.
          '<$1$2$3=$4'.XOOPS_URL.'/$5.html$6$7$8>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5.$6+$7.html$8$9$10>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5.$6+$7+$8+$9.html$10$11$12>'
        // Replace URLs of modules' directry.
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+index.htm$6$7$8>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.htm$7$8$9>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8.htm$9$10$11>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8+$9+$10.htm$11$12$13>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8+$9+$10+$11+$12.htm$13$14$15>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8+$9+$10+$11+$12+$13+$14.htm$15$16$17>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8+$9+$10+$11+$12+$13+$14+$15+$16.htm$17$18$19>'
        , '<$1$2$3=$4'.XOOPS_URL.'/$5+$6.$7+$8+$9+$10+$11+$12+$13+$14+$15+$16+$17+$18.htm$19$20$21>'
    );

    
$s = preg_replace($in$out$s); 
//    
$s = preg_replace('/<([^>]*)>/i','{\1}', $s);
//    
$s = $s.'';
    return 
$s;    
}


But we could also add module-specific rewrites (in separate config files like coRewriteModule.ini.php?). Just look at the great job Wishcraft did for some popular modules:
This is the modification for SEO paths for News 
RewriteRule 
^news/([a-zA-Z0-%_-]+)/([a-zA-Z0-%_-]+)/comment_([a-zA-Z0-9&%?_.-=]+) modules/news/comment_$[L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/([a-zA-Z0-%_-]+)/images/(.*) modules/news/images/$2  [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/images/(.*) modules/news/images/$2  [L,NC,QSA]
RewriteRule ^news/images/(.*) modules/news/images/$2  [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/([a-zA-Z0-%_-]+)/([0-9]+) modules/news/article.php?storycategory=$1&story_title=$2&storyid=$3  [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/([a-zA-Z0-%_-]+)/ modules/news/article.php?storycategory=$1&story_title=$2  [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/([0-9]+),([0-9]+) modules/news/index.php?storycategory=$1&topic_id=$2&start=$3  [L,NC,QSA]
RewriteRule ^news/([a-zA-Z0-%_-]+)/ modules/news/index.php?storycategory=$1  [L,NC,QSA]
RewriteRule ^news/([0-9]+),([0-9]+) modules/news/index.php?topic_id=$1&start=$2  [L,NC,QSA]
RewriteRule ^newsmodules/news/index.php  [L,NC,QSA]
RewriteRule ^news modules/news/index.php  [L,NC,QSA]
RewriteRule ^news/article.php?storyid=([0-9]+) modules/news/article.php?storyid=$[L,NC,QSA]


We could create a working platform where XOOPS users can add rewrite plugins per module (like the one above). This smarty output filter can save us a lot of time hacking our php files.

Dugris and others, what do you think of this concept?

24
jayjay
Re: URL changer
  • 2008/6/16 7:23

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


Quote:

frankblack wrote:
So finally I solved it by hacking the pagenav.php.


Hi frankblack!

How did you solve the pagenav problem? I hacked class/pagenav.php and changed this
$this->url $_SERVER['PHP_SELF'].'?'.$extra_arg.trim($start_name).'=';

to this
$this->url $_SERVER['REQUEST_FILENAME'].'?'.$extra_arg.trim($start_name).'=';


REQUEST_FILENAME = REQUEST_URI minus QUERY_STRING

I really hope this (and more) smarty filters get added to the core! If xoRewriteModule makes it to the core, please add the above fix

25
trabis
Re: URL changer - string support for xoRewriteModule
  • 2008/6/16 22:36

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I jayjay, thank you for the links.
I like suin´s idea, I have looked to something similar in the cbb or newbb SEO hack.

My idea for rewriting Urls is this:

.htaccess to redirect all pages not found to

http://www.yoursite.com/modules/seomodule/index.php?route=

one example could be:

http://www.yoursite.com/mynews/myarticle/mystoryid/5

would redirect (without notice) to

http://www.yoursite.com/modules/seomodule/index.php?route=mynews/myarticle/mystoryid/5

Then we could work with the params, change globals($_GETs, $xoopsModule, $_SERVERs, etc) and include the matching file.

We would only need an array containing the rewriting rules.
For coding urls we would use it with the suin's method (ablosutize ,search and replace).
For decoding we would invert the array.

Example
('module/news' => 'mynews') for module name;
('article.php'=>'myarticle', 'index.php'=>'myindex') for pages
('storyid'=>'mystory', 'topicid'=>'mytopic') for args

We could use a class to set this array making simple for user to add rewrite rules. Its a rough idea but has produced good results in my test site.

What is your idea on how the urls should look like?
site.com/modulename/pagename/argname1/argvalue1/argname2/argvalue2
site.com/modulename/pagename/argname1-argvalue1+argname2-argvalue2
site.com/modulename/pagename-argname1.argvalue1-argname2.argvalue2

????

26
jayjay
Re: URL changer - string support for xoRewriteModule
  • 2008/6/17 9:23

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


Hi trabis,

Thanks for joining the conversation! I love your idea of module-izing this. You make it look easy

I like this style:
https://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=64076&forum=30


becomes

https://xoops.org/forum/30-64076-flat/url-changer


So I would ditch the argnames as much as possible (why substitute words like viewtopic or forum when there's no need in mod_rewrite?) and use a combination of slashes and hyphens. I used slashes to delimit the module name, the query string stuff and the page title. This way we limit the amount of special characters in the url, which makes it easier to remember for us humans.

I would go for hyphens because Google will see underscores and some other characters as part of a word and hyphens as word delimiters.

I also suggest attaching (part of) the current pagetitle to the end of each url. I know it can be retrieved with the smarty tag <{$xoops_pagetitle}> in Xoops, but I don't know if you use smarty in your SEO module.

Thanks for your SEO work with Xoops!

27
trabis
Re: URL changer - string support for xoRewriteModule
  • 2008/6/17 12:50

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


The problem is that htacess will not take care of the args as the other rewrite scripts do. It will be just 4 or 5 lines to redirect every file notfound.

So the rewriter must know what this represent: 30-64076-flat
You could be simple if ther args order and number were every time the same...
We must map them, for save space we could add a special arg at the beggining to be used by the rewriter.
example:
7-30-64076-flat

Where 7 will do a trick for us. Imagine a binary number 00000111 = 7;

You could know that 1, 2 and 3 argument were being used for module = forum. Then the forum map would tell us the name of 1, 2 and 3

We could afford up to 8 variables per file with onlya number that could bo to 256!

Yeah, I´ll try this

28
seobrain
Re: URL changer - string support for xoRewriteModule
  • 2008/6/17 13:04

  • seobrain

  • Just popping in

  • Posts: 10

  • Since: 2008/6/17


nice, very interesting ideas

29
trabis
Re: URL changer - string support for xoRewriteModule
  • 2008/6/21 23:01

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


So at this point I have the script set for this:
http://www.yoursite.com/modules/seo/mynews/article/1-1

with .htacess you can then short it to
http://www.yoursite.com/mynews/myarticle/1-163

we could later set extra rewriting to short even more like:
http://www.yoursite.com/mynewsarticle/1-163

we could also think of adding meaningless stuff at the end like:
http://www.yoursite.com/mynewsarticle/1-163/my_title_goes_here.html

whatever, this will include:
http://www.yoursite.com/modules/news/article.php?storyid=163

In 1-163, 1 stands for storyid and 163 for the value. I´m using that binary logic associated with the module rules to achieve this.

The news plugin (not finished) is looking like:
seoversion.php:
$seoversion['name'] = 'mynews';
$seoversion['pages'] = array('index.php'=>'myindex','article.php'=>'myarticle');
$seoversion['args'] = array('storyid','storytopic');
?>

Binary thinking:
storyid=1
storytopic=2

...=4
...=8
...=16
..etc

If url was using both storyid and storytopic then it would pass number 3 (1+2) being the first arg related to storyid and second arg for storytopic

The url is inputed directly in the browser. Now I have to work the auto-rewrite of site urls wich is the worst part of it.

30
jayjay
Re: URL changer - string support for xoRewriteModule
  • 2008/6/23 13:07

  • jayjay

  • Not too shy to talk

  • Posts: 175

  • Since: 2003/9/10


That's great news!

I hope to test your beta release soon

Login

Who's Online

316 user(s) are online (112 user(s) are browsing Support Forums)


Members: 0


Guests: 316


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits