I understand that there may be other questions regarding vanity urls but everyone i see has a different code that i guess does the same job. Therefor i do not understand what rules are best for my personal question, that being said here is my question.
I simply want to create this,
127.0.0.1/website/profile.php?id=1
To this,
127.0.0.1/website/profile/Admin
My sub questions are also,
I understand the .htaccess file has to be in the root directory, but is that the root of my website or my xampp htdocs?(e.g c:/xampp/htdocs/ or c:/xampp/htdocs/website)
Using php should i make the conversion between id to username for the URLS on a seperate file then redirect to the requested user's page?
Thank you for reading, i just can't seem to get my head around .htaccess!
Root directory of your website.
No need for redirects. The way it works is that you can map every section of your URL to a URL parameter. For example, http://localhost/profile/Admin is really interpreted as http://localhost/website/profile.php?username=Admin. Only users will see the vanity URL; PHP will still see the URL parameters. In your case, the .htaccess rule will look something like ^profile/([0-9]+)$ profile.php?username=$1 (I obviously don't know for sure since I don't know the architecture of you site).
On a side note you might find Virtual Hosts interesting. It's a way of being able to create your own local domain for your site, for example http://my-local-website instead of using http://localhost/website or waiting to test in production.
More info here: http://sawmac.com/xampp/virtualhosts/
Related
I'm wondering how I can store tags in a url without the ? and without keys.
eg. Google Product forums does this: http://productforums.google.com/forum/#!topic/analytics/8qtK861a0iU
Each topic wouldn't have it's own directory and so a server side script determines which topic to show visitors.
Does anybody know how it is possible to do this with PHP?
Thanks
Google use a range of software to do this. one of which, can be done using .htaccess used on Apache servers (not IIS)
This is called modrewrite. A URL below can show an example of such tasks:
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
Do start learning this, upload a file called .htaccess to your Apache driven webserver.
I made one website xyz.com using php codeigniter framework. This website has modules, so modular extension is used. Now when this website is made live, every link shows index.php. So for this we can use .htaccess for modrewrite command. Till now my knowledge was cool enough. Now when my friend who has good knowledge of SEO saw my website links, he told me that your website will not come above(lower ranks) in google.
His reason is - your every request is pased through index.php. When google crawls your site, it will be redirected again to index.php which is main drawback. As he didnt have much knowledge about codeigniter, he told to fix this index.php issue as soon as possible. So I wanna know
IS HE GIVING A VALID REASON?? if yes...so how can I solve this problem.
Anything related to this issue from your side is also welcomed, as I may not have asked complete question.
Well, after your comment I can say that your friend is wrong. Google bot will never be redirected on the same page (index.php in your case). Of course is not very good that in each page url you have the "index.php" because you are losing important chars which otherwise can be used to put keywords.
Said that, your site will be indexed normally. Infact, many Joomla-based websites have the same behavior as you can see on this website (parlaritaliano.it) which is very well indexed on Google.
Anyway, I advice you to replace (using .htaccess) the index.php in every of your urls because it is better from a SEO point of view. I repeat...better, it does not will cause any Google bot loop.
I have a web app of which I would like to create a mobile version with jQuery Mobile. The existing application is built in CodeIgniter; I'll be using the same controllers, models where I can; (especially models since I'll be needing the same data anyway, might have to write new controllers).
I'm a bit confused as to how to get started. I want to put my mobile version on a subdomain (m.myhost.tld), however.. since my app is at www.myhost.tld and I don't feel like copying it all over to another folder and maintain two, I'm a bit confused.
I know I can use the User Agent library in CodeIgniter to detect mobile browsers and load views accordingly; I just don't know how to get this working with a subdomain. Do I need to customize my app/config/routes.php file here, or can I fix this with some .htaccess magic? I have next to none experience with .htaccess though. The only thing I know is how to remove my index.php from CI apps, and that's a copypasta snippet.
EDIT: I wonder if I can use a tutorial like this one to do what I want to do? It seems to be doing more or less the same thing, just with dynamic usernames instead of a simple 'm.'
EDIT 2: Some more information, I guess.
Say I detect mobile browsers using the User Agent library included with CodeIgniter. I want to direct these browsers to m.myhost.tld. However, the content that I want to display on the mobile website comes from a controller called mobile which I can also access through www.myhost.tld/mobile/; so my question is if there is a way to route a URL like.. for example www.myhost.tld/mobile/about to m.myhost.tld/about. I'm not even sure if this is possible, teehee. Still learning!
I'll be grateful for any advice you can give me. Thanks a lot!
If you want to share the same files in different hosts, you must assign the document root folder of your sites in your web server, this is an explanation for static files, but is the base to you understand.
browser -> host:z.y.xxx[ip.ip.ip.ip] -> web server -> read filesystem : document root + browser request path
so if your document root is:
/hosting/http/z.y.xxx/htdocs
and the request is /path-to-static/index.html the server try to read:
/hosting/http/z.y.xxx/htdocs/path-to-static/index.html
In conclution, you create the new host m.mysite.tld in your web server and you change the document root as the same of the you www.mysite.tld also you could use directives of host alias, like Apache ServerAlias directive. Have lot of documentation to how you could configure a web server.
You could handle the host name in php with $_SERVER['HTTP_HOST'] variable.
If you could specify more, I could help more.
have a nice day
I have used the Apache Mod Rewrite for PHP but not in IIS.
BACKGROUND:
I have inherited over 400 sites on IIS with PHP all with a copy of the identical code base.
The current code base has a unique connection string per client and that is why it was copied over and over again.
Each being a subdomain pointing an individual site in IIS:
customer1.mysite.com
customer2.mysite.com
I have used Sessions and PHP to get to a single code base with each site pointing to its own directoy that contains a single PHP file that pulls variables from the database master table and places them into Session strings using a virtual directory for the now single code base.
But now I want to take it a step further. The idea for this came from using Zend bootstrap with Apache.
My next step is to eliminate the indiviual PHP files and use a bootstrap file along with a single code base in a single directory on a single IIS site. www.mysite.com
QUESTION
I want to know if it is possible to do a rewrite rule so that any subdomain on mysite.com goes to mysite.com/bootstrap.php thus customer1.mysite.com goes to www.mysite.com/bootstrap.php and customer2.mysite.com goes to www.mysite.com/bootstrap.php but the subdomain stays in tack - even though it is just one site.
So that a call to: customer1.mysite.com goes to www.mysite.com and the bootstrap can read the subdomain, look up the site parameters, place them in sessions, and then allow access to the site.
Or if you know of a better way to accomplish this please let me know but I cannot change the 400 plus subdomains the clients are using to access the product.
If you are using ISAPI Rewrite (A ModRewrite for IIS), you could have your bootstrap.php look at the "X-Rewrite-URL" HTTP header, which is the original, unmodified, URL, and make a decision on what to show based on that.
Rewrite would not work because the wildcard is not allowed. So I had to add each subdomain to a single folder. A little more work but it solved the problem.
I have been looking for a while now to find a solution to accomplish the following system.
I would like to build a PHP system on, let's say, domainA. On this domainA I will allow an administrator to 'create' a new website. This website contains only of pieces of text, which are all stored in a database. This, I know how to do.
However, now I would like to make it possible that visitors that surf to domainB will be invisibly redirected to for example domainA.com/gateway.php?refdomain=domainB&page=xxx or something similar.
I have a vague idea this should be done by .htaccess, but I don't really know how I can do this in the most easy way. If for example there are some POST or GET requests on domainB, this should keep working. Also images linked to http://www.domainB.com/test.gif should be invisibly loaded form www.domainA.com.
I also know there are some CMS systems (eg drupal) which allow this feature, so it is possible, I just don't know how.
Thank you for any advice that might point me in the right direction,
kind regards,
Digits
Are you hosting both of these on the same machine? If so, something like VirtualHosts in Apache could solve this for you.
mod_alias and mod_rewrite might also be of some use to you.
Basically, you'll want to point all your domains to the same directory (maybe using a wildcard in your vhosts) and then setup urlrewrite; look at this question for an example, and it can be in a .htaccess file or Apache configuration.
All requests that come in will go to the same gateway.php and you can extract the current domain and requests using $_SERVER['REDIRECT_QUERY_STRING'], $_SERVER['REQUEST_URI'] and $_SERVER['SERVER_NAME'] for example. See $_SERVER. You'll then be able in your gateway.php to send the correct files.
If you use a CMS like Drupal, you should be able to assign these using the Portal Alias. By using the alias you will be able to assign different domains to point to different "sites" that are created.
OK, here's a really simple example:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domainA\.com
RewriteRule (.*) http://www.domainA.com/gateway.php?realpath=$1 [L,QSA]
You could then parse "realpath" in your gateway script using parse_url and take the appropriate actions.
You could get more complex with your rewrite rules to have separate ones for images, etc. if you wanted to
You could use the redirect header..