Question

I would like to map "http://www.example.com/abc" to "http://www.example.com/test/abc" for having the shortest route possible. I am using pyroCMS for my users and content.
the default pyrocms file:

# Multiple Environment config  
# Set this to development, staging or production  
# SetEnv PYRO_ENV production  

<IfModule mod_rewrite.c>

    # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes
    # disable the Apache MultiViews directive if it is enabled on the server. It plays havoc with URL rewriting
    Options -MultiViews
    RewriteEngine on

    # Keep people out of codeigniter directory and Git/Mercurial data
    RedirectMatch 403 ^/.*/(vendor|composer\.json|composer\.lock|system/cms/cache|system/codeigniter|system/cms/config|system/cms/logs|\.git|\.hg).*$

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

I would like to add this rule to the file:

RewriteRule ^([a-z0-9_]+)$ test/$1

To rewrite "BASE_URL/abc" to "BASE_URL/test/abc"

However,

i tried many positions as to where to put this RewriteRule, my website keeps giving a "Page Missing".

Is my RewriteRule ok? And where do i insert it?

Was it helpful?

Solution 2

It all depends on what your rule is supposed to do and how it is supposed to interact (or not interact) with the rest of your site. And considering your entire htaccess file is mostly commented out code (which I removed to make it halfway readable), you just want to place it under RewriteEngine On.

However, since it blindly routes everything into test you need to add a few conditions and make it something lilke:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/test%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/test%{REQUEST_URI} -d
RewriteRule ^([a-z0-9_]+)$ test/$1 [L]

OTHER TIPS

PyroCMS has built-in modular routing ability. see here:

http://docs.pyrocms.com/2.2/manual/developers/basics/modular-routing

If your "http://www.example.com/abc" refers to a custom module,then, you can add a file named "routes.php" in a in config folder of your module. the folder construction should like this :

addones/shared_addons/modules/your-module/config/routes.php

OR even you can edit the core route config file located at system/cms/config/routes.php and add this line or whatever your routing rules are:

$route['abd'] = 'test/abd';

OR more even, at your control pannel there is a redirect module that you can add redirections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top