I have URL that looks like this example.com/test-page/now_here, but I want the URL to look like example.com/test-page/now-here.
I have tried the following in my .htaccess file:
RewriteRule ^(/?test-page/.*/[^/]*?)_([^/]*?_[^/]*)$ $1-$2 [N]
RewriteRule ^(/?test-page/.*/[^/]*?)_([^/_]*)$ $1-$2 [R=301]
But it did not work. I get a 404 error when I goto /test-page/now-here
What am I doing wrong?
Here is my full .htaccess:
Options -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^example\.com$
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteRule ^(/?test-page/.*/[^/]*?)_([^/]*?_[^/]*)$ $1-$2 [N]
RewriteRule ^(/?test-page/.*/[^/]*?)_([^/_]*)$ $1-$2 [R=301]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
<IfModule mod_headers.c>
<If "%{REQUEST_SCHEME} == 'https' || %{HTTP:X-Forwarded-Proto} == 'https'">
Header always set Strict-Transport-Security "max-age=31536000"
</If>
</IfModule>
UPDATE
@MrWhite solution did work, and now when I goto the url test-page/now_here it goes to test-page/now-here, however its not going to my php method in my test page controller, here is the full code:
class TestPage_Controller extends App_Controller {
function index() {
$this->smarty->assign('currentPage', 'testpage');
$this->smarty->assign('pageTitle', 'Test Page');
$this->smarty->assign('description', "This is a test page.");
$this->smarty->display(MDCHAT_THEME . '/page_meta.tpl');
$this->smarty->display(MDCHAT_THEME . '/page_header.tpl');
$this->smarty->display(MDCHAT_THEME . '/test_page.tpl');
$this->smarty->display(MDCHAT_THEME . '/page_footer.tpl');
}
function now_here() {
$this->smarty->assign('currentPage', 'testpage');
$this->smarty->assign('pageTitle', 'Test Page');
$this->smarty->assign('description', "This is a test page.");
$this->smarty->display(MDCHAT_THEME . '/page_meta.tpl');
$this->smarty->display(MDCHAT_THEME . '/page_header.tpl');
$this->smarty->display(MDCHAT_THEME . '/here.tpl');
$this->smarty->display(MDCHAT_THEME . '/page_footer.tpl');
}
}
All I get when I goto test-page/now-here I get a blank white page even after I turned on php errors via php.ini display_errors = on and in my php code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
Still just a white screen.