Friendly URL and htaccess file - .htaccess

I'm trying to create a short and friendly link so that when the server receives the petition it will redirect you to the real link of the website.
Example:
This is the real link: mywebsite.com/profile.php?user=MikeRubio55
And I want it to look like this for sharing purposes: mywebsite.com/MikeRubio55
So what I'm looking for is the server receives this link (mywebsite.com/MikeRubio55) and automatically redirect and display this url (mywebsite.com/profile.php?user=MikeRubio55)
I've been searching for solutions and trying to make some changes to the .htaccess file to achieve this purpose but up until now I've had no success unfortunately.
Thanks in advance for all your suggestions and help.

Related

Tracking htaccess redirects?

is it possible to track htaccess redirects (without Google Analytics)? I would like to know how many people visit a certain (redirect) URL.
The use case is as follows:
The folder 'links' on my server has a htaccess file in it with all the redirects.
I would like to know how many people visit 'links.DOMAIN.com/topic' and, thus, get redirected to https://somethingelse.com.
We don't use any Google products. Analytics would otherwise be the obvious choice.
I'm out of ideas, tbh.
Thank you in advance! :)

Track from where link is clicked node.js

I'm trying to track from where my links are clicked.
Exemple I place a link to my website on facebook, instagram, linkedin.
I would like to know where my link is clicked most of the time.
bit.ly does it and I don't know how.
One of my ideas was to identify links like
www.exemple.com/facebook_url
www.exemple.com/instagram_url
but if I can avoid this it would be perfect.
Any idea ? :)
I found how !
req.headers.referer;
give me the url used to redirect my user :)
The simplest way to do this would be to set up a web server with redirects and analytics already built in. You could also build your own analytics using a redirecting html + js
If you have access to a webserver, you could use PHP to do a conditional redirect.

Issue Regarding .htaccess Redirection

I have some issue regarding .htaccess redirection. I have checked a post regarding .htaccess redirection of one page to another domain page.
How to redirect a single web page from one domain to another using .htaccess
I have tried these code but when i use this code it is getting redirected but all the other pages on the old domain website are showing 404. Please help me.
Please note: I am not a developer and don't have any knowledge about the codes so please provide a simple solution so that i can directly implement on the website. I will be very greatful to you.....:)

Custom URL in Codeigniter using htaccess

I am developing a site on Codeigniter 2.0.2 . Its a site where companies/users can signup and create their own profile page, have their own custom url(like http://facebook.com/demouser), have their own feedback system, display their services.
This said, I have been successful in display the profile page in the following format
http://mainwebsite.com/company/profile/samplecompany
This displays the home page for the company samplecompany , where company is the controller and profile is the method.
Now I have few questions,
I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working.
There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form
`
http://mainwebsite.com/company/profile/samplecompany/feedback or
http://mainwebsite.com/samplecompany/feedback
http://mainwebsite.com/company/profile/samplecompany/services or
http://mainwebsite.com/samplecompany/services
http://mainwebsite.com/company/profile/samplecompany/contactus or
http://mainwebsite.com/samplecompany/contactus
wheresamplecompany` is the dynamic part
Is it possible to create site links in the format?
I understand using A record for a given domain, I can point a domain say, http://www.samplecompany.com to http://mainwebsite.com/company/profile/samplecompany so typing http://www.samplecompany.com he should be taken to http://mainwebsite.com/company/profile/samplecompany . If this is successfully implemented, will
http://www.samplecompany.com/feedback
http://www.samplecompany.com/services
http://www.samplecompany.com/contactus
work correctly?
I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working.
There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form ` http://mainwebsite.com/company/profile/samplecompany/feedback or http://mainwebsite.com/samplecompany/feedback
You can accomplish this using routes. For example, in your /config/routes.php file, put this:
$route['samplecompany'] = "company/profile/samplecompany";
$route['samplecompany/(:any)'] = "company/profiles/samplecompany/$1";
The first rule tells CodeIgniter that when someone accesses http://mainwebsite.com/samplecompany that it should process it as if the URL were "company/profile/samplecompany". The second rule captures anything that comes in the URI string after "samplecompany" and appends it onto the end.
However, if you have multiple companies(not just samplecompany), you're probably going to want to extend CI's router to suppor this unless you want to manually edit the config file each time a new company is added.
OK, you're definitely going to want to handle dynamic company names(as per your comment). This is a little trickier. I can't give you the full code, but I can point you in the right direction.
You'll want to extend CI's router and on an incoming request query the DB for the list of company names. If the URI segment matches a company name, you'll want to serve it up using your company/profile method. If it does not, you will ignore it and let CI handle it normally. Check out this post on this topic for more information: forum link.
Here's a great guide on how to achieve what you need: Codeigniter Vanity URL's.

Dynamically creating URLs for other websites

I'd like to know how websites have created URLs with other domains like these on trafficestimate.com.
I'm guessing it's some .htaccess stuff to redirect domain names to a dynamic page?
Thanks
Your URL has an GET Request. So when someone calls the page http://google.com/search with the parameters hl=en, safe=off etc., the page can process those parameters. So for instance safe=off means that you want to get back any search result. The q=site:... is your search string. In this case Google will look it up in its database and give you the results. So when you call this URL there is probably no .htaccess processing done. However you can process the URL and GET request with .htacces and i.e. redirect the user to another page.
Maybe you'll describe a bit further what exactly you trying to do/want to know. This makes explaining easier.
EDIT: After reading Gumbo's comment I looked at the Google result page. So maybe your question means the trafficestimate-URLs. They look like http://trafficestimate.com/example.org. This is really a good case for .htaccess. So using .htaccess they take the URL and redirect it to http://www.trafficestimate.com/websites/?domain=example.org. Here you have again a GET request and an application builds the page.
Some URL rewriting is probably involved. Otherwise they would have to create an existing file for every possible request.
Using Apache’s mod_rewrite in a .htaccess file is one option. But since the server identifies itself with “Microsoft-IIS/7.5”, they are probably rather using ISAPI_Rewrite, a mod_rewrite derivative for Microsoft’s IIS.

Resources