D
D
Danil Shirokikh2012-08-03 09:22:16
Apache HTTP Server
Danil Shirokikh, 2012-08-03 09:22:16

How to specify title in htaccess for specific url?

There is an unknown CMS, which is very difficult to understand. And there is a task - to set the title I need for a specific page of the site. I read somewhere that this can be done in htaccess.
Question: how?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Ramzeska, 2012-08-03
@Ramzeska

Create a file:

<?
$rewrite['/'] = 'Новый тайтл';
$rewrite['/about/'] = 'Новый тайтл';

ob_start("titler");

function titler($content) {
    global $rewrite;
    if (isset($rewrite[$_SERVER['REQUEST_URI']]))
        return preg_replace("#<title>.*?</title>#",'<title>' . $rewrite[$_SERVER['REQUEST_URI']] . '</title>');
    else return $content;
}

And add a flag to .htaccess:
php_value auto_prepend_file "titler.php";
Either include the engine somewhere in config.php.
Just keep in mind, this is a very cool crutch - it's better never to do this :)

A
Anton Fedorov, 2012-08-03
@datacompboy

In the general case, this cannot be done.
If an unknown CMS displays any query parameters (the part after ?xxx) as a title, then these are its personal features (very negative).

A
AxisPod, 2012-08-03
@AxisPod

You can specify in .htaccess if you implement it, but it will be a great crutch. Or, as an option, if the server has a filter module that will allow you to do this.

M
MiXei4, 2012-08-03
@MiXei4

If there is a problem with the code, then you can pervert like this:
At the end of the index.php index file or whatever you have
Check $_SERVER['REQUEST_URI'] for a match with the desired url and if there is a match, output something like this
echo '' ;
The header will be replaced with javascript.

A
Andrey Nekhaychik, 2012-08-03
@gnomeby

There is a module for Apache Filter where you can configure the replacement of HTML under conditions, but this is a cruel crutch. For this you have to hit on the hands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question