I am using codeignator and I have to redirect URL. I have two URL which are as follows
https://example.com/contact-us/
https://example.com/about-us/who-we-are/
I don't have any contact
and about-us/who-we-are/
controller name or view in my codeignator project.
Let's talk about exist URL
I am removing the index.php and controller name from the URL.
So my old URL is
https://example.com/index.php/Menu_control/aboutus
Now new URL is
https://example.com/aboutus
//$route['(:any)'] = 'Menu_control/$1';//remove the controller name
Now when user enter the URL https://example.com/contact-us/
then it should be redirect on https://example.com/aboutus/
Same as on my second URL https://example.com/about-us/who-we-are/
to redirect on https://example.com/services/
I tried some code in .htaccess but it's not working for me.
Redirect 301 "https://example.com/contact/" "https://example.com/aboutus/"
Would you help me out in this issue?
Finally I found my answer. I don't know it's best or not but solved my issue.
I added code in .htaccess
RewriteRule ^contact-us/ https://example.com/aboutus [R=301,L]
RewriteRule ^about-us/who-we-are/ https://example.com/services/ [R=301,L]
When user enter URL https://example.com/contact-us/
then it will redirect on https://example.com/aboutus
Adding a RewriteRrule to the top of the .htaccess after the RewriteBase / file solved the problem.
RewriteRule ^foo/$ /foo/bar [R=301,L]
The Apache Redirect
directive should work. I think the failed attempts at using it are due to syntax mistakes. The second argument (the one after the status) needs to be a URL-path, not a URL. A subtle, but important distinction.
Try these in .htaccess
Redirect 301 "/contact" "https://example.com/aboutus"
Redirect 301 "/about-us/who-we-are" "https://example.com/services"
And, as I'm sure you know, but I feel compelled to point out, make sure the "alias" module (mod_alias) is enabled.