Dear community,
I am building a multi-lingual website and coded the prettyURL functionality myself by redirecting every URL request to "index.php" (as specified in the .htaccess file):
.htaccess
In the "index.php", I then declare all the CouchCMS editables and require a specific .php file based on some previous code.
index.php
Everything is displayed properly, working all fine. The only issue is that because of the single-point entry through "index.php", all the CMS fields are displayed within one template in the admin panel (that template clearly links to "index.php", as seen when hovering over it --> see screenshot below).
For the sake of usability, I would like to have different templates for each of the files in the admin panel (e.g. "home", "about", "404", ...) instead of having all the fields for all the pages listed in one long list in one single template. But I do not know how that would be possible to do with a single point entry.
The single-point entry is important to me, though, because the redirect functionality I need seems impossible to do within the .htaccess alone. That's because I have a few different redirects happening:
1.) if "/", go to "home.php"
2.) if "/en", go to "home.php" as well
3.) if "/en/home", go to "home.php" as well
4.) else, go to "404.php"
Thank you for your support.
All the best,
andi
I am building a multi-lingual website and coded the prettyURL functionality myself by redirecting every URL request to "index.php" (as specified in the .htaccess file):
.htaccess
- Code: Select all
RewriteEngine On
# if the requested url query is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# and if the requested url query is not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# always redirect to "index.php"
RewriteRule ^(.*)$ index.php
In the "index.php", I then declare all the CouchCMS editables and require a specific .php file based on some previous code.
index.php
- Code: Select all
<?php require_once( "../couch/cms.php" ); ?>
<?php
// some queries performed here
?>
<cms:set my_lang = "<cms:php>echo $GLOBALS['selected_lang'];</cms:php>" />
<cms:template title="Home">
<cms:editable name="home_h1" type="text" />
<cms:editable name="home_paragraph_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
<cms:editable name="home_paragraph_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>
<cms:template title="About">
<cms:editable name="about_h1_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
<cms:editable name="about_h1_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
<cms:editable name="about_paragraph_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
<cms:editable name="about_paragraph_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>
<cms:template title="404">
<cms:editable name="error_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
<cms:editable name="error_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>
<?php
// REDIRECT TO ACTUAL PAGE
// 1.) if no query in URL, go to home page
if ( empty($qs_part1) ) {
require_once($qs_part2 . ".php");
}
// 2.) if only language is in query string but nothing else, go to home page as well
else if ( !empty($qs_part1) && empty($qs_part2)
&& in_array($qs_part1, $available_languages)
) {
require_once($qs_part2 . ".php");
}
// 3.) if language and filename are in query string, go to home page as well
else if ( !empty($qs_part1) && !empty($qs_part2)
&& in_array($qs_part1, $available_languages)
&& in_array($qs_part2, $pagesFilenames)
) {
require_once($qs_part2 . ".php");
}
// 4.) else if page does not exist, go to 404 page
else {
require_once("404.php");
}
?>
Everything is displayed properly, working all fine. The only issue is that because of the single-point entry through "index.php", all the CMS fields are displayed within one template in the admin panel (that template clearly links to "index.php", as seen when hovering over it --> see screenshot below).
For the sake of usability, I would like to have different templates for each of the files in the admin panel (e.g. "home", "about", "404", ...) instead of having all the fields for all the pages listed in one long list in one single template. But I do not know how that would be possible to do with a single point entry.
The single-point entry is important to me, though, because the redirect functionality I need seems impossible to do within the .htaccess alone. That's because I have a few different redirects happening:
1.) if "/", go to "home.php"
2.) if "/en", go to "home.php" as well
3.) if "/en/home", go to "home.php" as well
4.) else, go to "404.php"
Thank you for your support.
All the best,
andi