XF 2.1 htaccess it looks so easy

stanleyb23

Member
Its giving me a headache, and I dont manage to get it.

I d like to rewrite /forum/post692957.html to /forum/posts/692957/

Cant be too difficult :)
 
Im reading and thinking it must be something like this:
RewriteRule ^post(.*)\.html$ /posts/$1/ [L,R=301,NC]

I tried this:
RewriteRule /post([0-9]+)\.html posts/$1/ [L,R=301,NC]

I tried this:
RewriteRule ^post([0-9]+)\.html$ /Forum/posts/$1/ [R=301,L]
 
Last edited:
I see whats happening, i used a script that loads html.php. Its a script that as far as i can understand, makes from:
about1234.html link---> t1234 --> in case t -- use 1234 and make a new url
this-is-a-topic-t1234.html -- same as above

but now /forum/post692957.html goed into the script and thats not working o_O

Or i need to put a htacces rule before it opens the html.php script that says when post is in the url do this and dont use the html.php script.
Or i need to add something in the html.php script.

This is inmy htaccess:
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^(.*)\.html html.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]



This is the script in html.php:
<code><?php

function phpbb_redirect($url)
{

//exit;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit;
}

function redirect_html()
{
if (!isset($_SERVER['REQUEST_URI']))
{
return;
}
$url = explode('/', $_SERVER['REQUEST_URI']);
$url = explode('.', array_pop($url));
if (array_pop($url) != 'html')
{
return;
}
$url = explode('-', array_pop($url));
$url = explode('u', array_pop($url));

$url = array_pop($url);
$type = substr($url, 0, 1);

/* get the next to last string */
if (is_numeric($type) == true && $type) { // There is pagination like are-you-a-new-member-introduce-here-t1737-10.html
$url_page = explode('/', $_SERVER['REQUEST_URI']);
$url_page = explode('-', array_pop($url_page));
$typestring = array_slice($url_page, count($url_page)-2, 1);
$typestring_check = $typestring[0];

//echo $url ."<br>";
//echo $typestring_check . "<br>";
//echo substr($typestring_check, 0,1) . "<br>";
$type = substr($typestring_check, 0,1);
//echo $type . "<br>";
//echo $type;
// if last string is int, its paginated
$id = intval(substr($typestring_check, 1));
$page = $url/10; //Division durch 10

//echo $page;
switch ($type)
{
case 't':
if ($id == 1){
phpbb_redirect('index.php?threads/' . $id . '/'); //redirect to first page
}else{
phpbb_redirect('index.php?threads/' . $id . '/page-' . $page); //redirect to paginated page
}
case 'f':
phpbb_redirect('index.php?forums/' . $id . '/');
}
} else { // No pagination (Maybe first page of the thread) like like are-you-a-new-member-introduce-here-t1737.html

$type = substr($url, 0, 1);
$id = substr ($url, 1);

//echo $id . "<br>";
//echo $type;
switch ($type)
{
case 't':
phpbb_redirect('index.php?threads/' . $id . '/');

case 'f':
phpbb_redirect('index.php?forums/' . $id . '/');

}

}
}
redirect_html();
include('index.php');</code>
 
I see whats happening, i used a script that loads html.php. Its a script that as far as i can understand, makes from:
about1234.html link---> t1234 --> in case t -- use 1234 and make a new url
this-is-a-topic-t1234.html -- same as above

but now /forum/post692957.html goed into the script and thats not working o_O

Or i need to put a htacces rule before it opens the html.php script that says when post is in the url do this and dont use the html.php script.
Or i need to add something in the html.php script.

This is inmy htaccess:
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^(.*)\.html html.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]



This is the script in html.php:
<code><?php

function phpbb_redirect($url)
{

//exit;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit;
}

function redirect_html()
{
if (!isset($_SERVER['REQUEST_URI']))
{
return;
}
$url = explode('/', $_SERVER['REQUEST_URI']);
$url = explode('.', array_pop($url));
if (array_pop($url) != 'html')
{
return;
}
$url = explode('-', array_pop($url));
$url = explode('u', array_pop($url));

$url = array_pop($url);
$type = substr($url, 0, 1);

/* get the next to last string */
if (is_numeric($type) == true && $type) { // There is pagination like are-you-a-new-member-introduce-here-t1737-10.html
$url_page = explode('/', $_SERVER['REQUEST_URI']);
$url_page = explode('-', array_pop($url_page));
$typestring = array_slice($url_page, count($url_page)-2, 1);
$typestring_check = $typestring[0];

//echo $url ."<br>";
//echo $typestring_check . "<br>";
//echo substr($typestring_check, 0,1) . "<br>";
$type = substr($typestring_check, 0,1);
//echo $type . "<br>";
//echo $type;
// if last string is int, its paginated
$id = intval(substr($typestring_check, 1));
$page = $url/10; //Division durch 10

//echo $page;
switch ($type)
{
case 't':
if ($id == 1){
phpbb_redirect('index.php?threads/' . $id . '/'); //redirect to first page
}else{
phpbb_redirect('index.php?threads/' . $id . '/page-' . $page); //redirect to paginated page
}
case 'f':
phpbb_redirect('index.php?forums/' . $id . '/');
}
} else { // No pagination (Maybe first page of the thread) like like are-you-a-new-member-introduce-here-t1737.html

$type = substr($url, 0, 1);
$id = substr ($url, 1);

//echo $id . "<br>";
//echo $type;
switch ($type)
{
case 't':
phpbb_redirect('index.php?threads/' . $id . '/');

case 'f':
phpbb_redirect('index.php?forums/' . $id . '/');

}

}
}
redirect_html();
include('index.php');</code>

Replace with this

Apache config:
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule forum/post([0-9]+)\.html forum/posts/$1/ [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^(.*)\.html html.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]

i.e add it after
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
No, something is going wrong.
Yhis is the url for example:

And this is the htaccess now:

# This line may be needed to workaround HTTP Basic auth issues when using PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule Forum/post([0-9]+)\.html Forum/posts/$1/ [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^(.*)\.html html.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
 
yes, this is working:
RewriteRule ^post([0-9]+)\.html /Forum/posts/$1/ [L,R=301,NC]

Hopefully this doesnt conflict with other urls because of the ^i used

Thanks very much for your help!

Maybe you are willing to help me with two more 404's:
This one /Forum/about70785.html&highlight without the &highlight the url redirects the way i like it.

And this one: /Forum/search.php?search_author=Ltajanssen
should be linking to https://www.klusidee.nl/Forum/members/ltajanssen.122575/#recent-content in a perfect world :)
or just to /Forum/members/
 
Last edited:
Top Bottom