-1

Quick question, is there a way to clean up URl's for an existing website? I mean lets say I have a existing link like this http://www.webawwards.com/website?id=320 but I want to make it http://www.webawwards.com/terna

Is there a way I could clean up that url but also if there is any existing links to current URL that the link would still go through?

Could you please direct me the right way? Thank you

TonyS
  • 17
  • 5

1 Answers1

0

If you want to hard-code the URLs into your .htaccess file you can simply set up static redirects:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{QUERY_STRING}  ^id=320(.*)$
    RewriteRule /website$ /terna [L,NC]

    RewriteCond %{QUERY_STRING}  ^id=321(.*)$
    RewriteRule /website$ /somewhere-else [L,NC]
</IfModule>

However if you want to make it more flexible (maybe let people change their own redirects, or similar) you'd need to store it in a database (redirects table, columns of website_id, redirect_url) then when someone queries, do this (pseudo-code):

if (isset( queryString['id'] ))
    query( SELECT redirect_url FROM redirects WHERE website_id = queryString['id'] )
    redirectTo( redirect_url );
    exit

In PHP, the actual redirect would be done with header('Location: ' . $redirect);, and the query part should be easy enough.

Joe
  • 15,669
  • 4
  • 48
  • 83
  • If I was to use .htaccess like in your example but the pages are dynamically generated? – TonyS Sep 23 '14 at 10:02
  • You can either wait till the page is generated then manually add the htaccess rule, or you can use a dynamic option such as the PHP alternative. htaccess can't do dynamic redirects, so you'd need to hardcode each one – Joe Sep 23 '14 at 10:03