简体   繁体   中英

Codeigniter htaccess redirections not redirecting to desired url

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.

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'] = '';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM