Reputation: 1
I have a codeigniter website which I want to do seo on. So i used routes for sluggish urls rather than the codeigniter default having method name and indices. With this a problem comes in play, three different urls it opens the same page ie.
1. https://www.example.com/seo-freindly-url/
2. https://www.example.com/index.php?/controller/method/42
3. https://www.example.com/controller/method/42
But I want only the first url to work, for others i want to redirect to the seo friendly one by only using htaccess redirections. Please Help me in that. One more thing i used htaccess 301 redirection to redirect one of my urls
Redirect 301 "/plan/index/42" https://www.example.com/services/seo
It works to some extent, whenever I open the url
https://www.example.com/plan/index/42
it redirects to
https://www.example.com/services/seo?/plan/index/42
but it has to be https://www.example.com/services/seo/
Thank you.
Upvotes: 0
Views: 469
Reputation: 4582
It's hard to test on my end, but you might try something like this:
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^controller/method/42$ /seo-friendly-url [L]
redirect 301 /plan/index/42 /services/seo
RewriteRule ^(system|application|cgi-bin) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Remove index.php from all URLs
RewriteRule .* index.php/$0 [PT,L]
/application/config/config
// This assumes you want to remove index.php from all URLs
$config['index_page'] = '';
Upvotes: 0