Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: URL redirect

  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    URL redirect

    I'm running a codeigniter page and I have a news/blog section. My news articles are accessible at:

    1) https://www.site.com/news/id24-
    and
    2) https://www.site.com/news/id24-AnyRandomText
    and
    3) https://www.site.com/news/id24-DatabaseTitle

    I want all versions of this to be redirected to "news/id24-DatabaseTitle"

    I've tried all i can think of to no avail. I'd really appreciate any help - any ideas?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you need to set a rule in your .htaccess file
    something like

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule news/id24(.*) news/id24-DatabaseTitle
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    you need to set a rule in your .htaccess file
    something like

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule news/id24(.*) news/id24-DatabaseTitle
    Thanks for this. I have this bit of code to the bottom of my .htaccess file and now get "500 Internal Server Error".

    Even if we can get this to work, it doesn't solve the root cause of the problem since each time I add a piece of news I will have to add a line to the .htaccess file indicating that all requests must be redirected.

    Can I do some codeigniter trickery to do this?

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you might be able to create a variable redirect

    RewriteRule (news)(\\/)((?:[a-z][a-z]+))(\\d+)(-)((?:[a-z][a-z0-9_]*)) news/id($3)-DatabaseTitle
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #5
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    you might be able to create a variable redirect

    RewriteRule (news)(\\/)((?:[a-z][a-z]+))(\\d+)(-)((?:[a-z][a-z0-9_]*)) news/id($3)-DatabaseTitle
    I'm not sure why but adding this hasn't made any difference. While i'm not getting the "500 Internal Server Error" - I'm still able to access the content using all 3 versions (id24-*). I suspect my routes.php file at (application\config\routes.php) may be involved. It contains this bit of code:

    Code:
    $route['news/id(\d+)-(.*)'] = "news/view/$1";
    If there was a way for me to retrieve the article title from the "news" database (column "title" corresponding to row id) I think the situation would be solved - at least in terms of removing "duplicate" content in the eyes of Google.

    At the moment, links to each individual News article are made from a sort of news index which dynamically generates the each news story URL using this:

    Code:
    <h2><a href="<?=site_url()?>news/id<?=$value->id?>-<?=$title?>" style="color:inherit; text-decoration:none;"><?=$value->title?></a></h2>
    Any thoughts?

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    yes that looks like it does pretty much the same thing
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #7
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Htaccess

    What is the rewrite rule for dynamic websites? Can anyone explain clearly the step by step construction of htaccess file?

  • #8
    New to the CF scene
    Join Date
    Feb 2013
    Location
    new delhi
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi To All !

    Forwarding a domain/subdomain to a website:

    To forward a domain without "www" (e.g. http://example.com) to a destination page, enter your destination URL in @ field and choose redirection type as shown in the figure below.
    To forward http://www.example.com (notice www) to a destination page, enter your destination URL in www field and choose redirection type as shown in the figure below.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •