Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong> I went through and tested this out on one of my servers. This works fine for me:</p> <pre><code>RewriteEngine On RewriteRule ^sub-site/([a-z_]+)/([a-z0-9_-]+)$ /sub-site/index.php?locale=$1&amp;page=$2 </code></pre> <p>This gets you most of the way there, but it doesn't do the locale translation (en => en_EN), it just delivers the locale as-is to the PHP script. Using mod_rewrite, I'd recommend RewriteMap; however, if you <em>only</em> have access to .htaccess (like on a shared host), you can't use RewriteMap.</p> <p>So then, to accomplish the locale translation, I think you'd be best off doing it on the PHP side. You could either use one of the frameworks listed below, or just do it yourself.</p> <p>In case you do have access to the virtual host configuration, you'd make a text file like:</p> <pre><code>en en_EN fr fr_FR ca fr_CA </code></pre> <p>If that file was located at /path/to/localemap.txt, you'd have:</p> <pre><code>RewriteMap locales txt:/path/to/localemap.txt RewriteRule ^sub-site/([a-z_]+)/([a-z0-9_-]+)$ /sub-site/index.php?locale=${locales:$1|en_EN}&amp;page=$2 </code></pre> <p>This defaults to en_EN if nothing's found in the map.</p> <p>Hope that helps!</p> <hr> <p>If you're just using .htaccess, then mod_rewrite will easily do what you want.</p> <ul> <li><a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html" rel="nofollow noreferrer">http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html</a></li> <li><a href="http://articles.sitepoint.com/article/guide-url-rewriting" rel="nofollow noreferrer">http://articles.sitepoint.com/article/guide-url-rewriting</a></li> <li><a href="http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/" rel="nofollow noreferrer">http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/</a></li> </ul> <p>You'd probably want to look into RewriteMap for your categories or locale, although you could just grab that part of the URL and use it as a parameter directly. Here's an example to get you started:</p> <pre><code>RewriteRule /sub-site/([a-z_]+)/([a-z0-9_]+) /sub-site/index.php?locale=$1&amp;page=$2 </code></pre> <p>You'd really want to narrow down the regular expressions used to make them more specific to your supported locales and categories, but I think it's a decent starting point.</p> <p>Other PHP frameworks, especially those focused on MVC, also provide similar URL routing functionality. Examples:</p> <ul> <li>CakePHP: <a href="http://book.cakephp.org/view/46/Routes-Configuration" rel="nofollow noreferrer">http://book.cakephp.org/view/46/Routes-Configuration</a></li> <li>CodeIgniter: <a href="http://codeigniter.com/user_guide/general/routing.html" rel="nofollow noreferrer">http://codeigniter.com/user_guide/general/routing.html</a></li> <li>Kohana: <a href="http://docs.kohanaphp.com/general/routing" rel="nofollow noreferrer">http://docs.kohanaphp.com/general/routing</a></li> <li>Yii: <a href="http://www.yiiframework.com/doc/guide/topics.url" rel="nofollow noreferrer">http://www.yiiframework.com/doc/guide/topics.url</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload