Cleaning up URL's for an existing Website - url

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

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.

Related

wildcard_charcters.sitename routing issues

i would like to incorporate wildcard characters to my site. so previously it was
www.mysite.com/user/mike or www.mysite.com/user/dave will look like
mike.mysite.com or dave.mysite.com. i tried .htacces rewriting but those were of rewriting for sub-domains and it was creating problems with css and images.I just want that too call user function with value we pass.I use RoR MVC framework.(i'm sure .htacces solve this issue but i don't know if we can give wildcards in routes too).
and i would like to keep other links normal like www.mysite/project/dashboard or www.mysite/project/messages.
Thanks in advance.
edit
i tried this but it dosent work, it's goes to site5s default page.
Options +FollowSymLinks
RewriteEngine On
RewriteCond ^(.*)$.example.com [NC]
RewriteRule ^(.*)$ http://example.com/user/$1 [R=301,L]'
ok, finnaly i was able to do it,there will be few things which you have to do first.
paste this code in .htaccess first of all.
Options +FollowSymLinks
RewriteEngine On
// enable rewriting
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ // Check for wildcard character before example.com
RewriteCond %1 !=www // check if www is not present in URL
RewriteRule ^(.*)$ http://www.example.com/user/%1/$1 [R=302,L] // Redirect URL and replace matched wildcard character "^(.+)" in place of "$1"
Now we have defined the rules for that, now it's turn of redirection. above code won't be able to work.
for that you have to create a wildcard sub domain in from your Cpanle. Create a sub domain *.example.com and point to your public_html(you subsite if t\redirected site is a child site)

prevent users from seeing full path

I want to know if there is a way to prevent visitors on the website to see the full site url .. so for example instead of http://www.5eren.dk/index.php all the user see's is http://www.5eren.dk .. is this possible ?
If i am understanding you correctly check out .htaccess rewrite condition and rewrite engine.
For example to hide a file extension:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
This should get you started.
Simply NO
However, depending on your server-side scripting technology you use on your website, such functionality may be applied by a mean of central script that call some URL on your website and render it as it is being the requested script with some param.
For example:
Suppose the following URL
http://myexample.com/secrets/pages/output.php
Now we may request it using some routing script as follows:
http://myexample.com/routing.php?routeID=123
Using some database inside your routing script you may able to call or include the secrets/pages/ouput.php

URL rewrite htaccess my website

I would like to be able to access this URL on my website:
www.mysite.com/author/username
trough this one
www.mysite.com/username
Please consider that people should be able to access using the two url and that the "username" always change depending on the user.
What would be the best way to do it? htaccess rewrite?
Thank for your time!
Seems like it could be messy and box you in if your users create names that match paths that overlap with existing or future paths.
RewriteCond %{REQUEST_URI} ^/[a-z]+$ #1
RewriteCond %{REQUEST_FILENAME} !-f #2
RewriteRule ^/([a-z]+)$ /author/$1 [P] #3
try to restrict it as much as possible to your username pattern
only rewrite if the path doesn't already exist
proxy to the /author/username version of the URL

don't display .php extension in address bar(php)

First of all this method clearly working on github, for example pages showing done:
https://github.com/account
https://github.com/inbox
There is no .php extension at all + not needed ?page=account or ?page=inbox
In my opinion it's done via .htaccess.
Maybe someone knows how it should look in order to archieve same effect like github site ?
This can be achieved using mod_rewrite for apache
You put a .htaccess file in your document root and give it rules (Regular Expressions) to match the called URLs with
It looks similar to this:
RewriteEngine On
# rule to call MyPage.php if you call the URL http://yourdomain.com/MyPage
RewriteRule ^(.*)$ $1.php
# rule to add GET params
RewriteRule ^(.*)$ index.php?page=$1
There are several tutorials regarding mod_rewrite on the internet

A little bit help in url rewriting, please!

I have a short question about url rewriting...
I have a website. Let's say http://www.example.com/
with some subsites:
http://www.example.com/a.php
http://www.example.com/b.php
etc...
and some "special" urls like
http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1
Now I would like to write a .htaccess file to convert current urls into rewritten urls like
http://www.example.com/a/
http://www.example.com/c/1/#link1
I'm not an expert in url rewriting, so could somebody please help me?
Best reagards.
RewriteRule ^a$ a.php [L]
RewriteRule ^c/(.*)/(.*) c.php?i=$1$2
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/
Should work as far as your static pages go, you can not rewrite the hash because the hash is not sent to the server (as discussed here). If you need to rewrite the hash I would suggest changing the hash to another GET variable (eg u), in that case just add this to your htaccess: RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2. If you simply intend to leave the anchor though, you can omit it from your rewrite and everything should be fine (...becuase the server never sees the hash/pound symbol), and in that case you should add this to your code RewriteRule ^c.php?i=(.*) c/$1/.

Resources