I'm developing a new website on a server that uses ~ for user directories. So the new site (old one is still online while developing) is hosted under domain.com/~cms/. Is that a problem? I never saw that before ... I know its not from outerspace but ... kind of uncommon isn't it?
I need to know if there is a proper solution via .htacces Redirect to rewrite all requests to that subdirectory BUT leave some old URIs like domain.com/dir1 or domain.com/dir2 untouched ...
Is that possible? I know some basic .htaccess stuff but since the live page is still up I dont want to fool around on this server without beeing sure :)
Thx!!
Related
I have changed my website from WordPress to Laravel framework but I want to hold my traffic when visit through old URL. How can redirect those visitors to new urls in simple way? I don't have much experience in code and command line.
Since you say that you need to redirect from old URL to new URL, you essentially say that you intend to leave your Wordpress site where it was and to ensure that the server redirects to a new URL. I will ignore the "simple way" part, as programming is considered anything but simple, but, in PHP you can redirect to a new URL via:
header('Location: '.$newURL);
however, you should think this through, because you have the option of setting up your new, Laravel version on the server where the old, Wordpress version is hosted. That would completely render your redirect task unnecessary and would probably be better financially, assuming that you need to pay for your Wordpress hosting as well.
I work as a web developer, creating custom websites for customers. My .htaccess files are generally very simple. I generally only do 2 things:
Create a custom ErrorDocument for 404 errors
Redirect the /upload directory to /admin/upload to simplify some shared code between the public website and the admin system
I have everything working okay, other than one slight annoyance I'm wondering if anything can be done about. I'm using php, and I try to design the websites in a modular fashion, so that it doesn't matter whether the code is hosted at "example.com/" (the real domain), "localhost/exampleproject2" (on my development machine), or "mycompanywebsite.com/example.com" (Where we host a "beta" version for the customer to view when we get to that point in development).
From the PHP side of things, I have no issues here. But so far as Apache is concerned, I have to create 3 slightly different .htaccess files for each of those domains:
ErrorDocument 404 /404.php
Redirect 301 /upload /admin/upload
ErrorDocument 404 /exampleproject2/404.php
Redirect 301 /exampleproject2/upload /exampleproject2/admin/upload
ErrorDocument 404 /example.com/404.php
Redirect 301 /example.com/upload /example.com/admin/upload
Obviously this is not a huge deal, but it is a bit annoying. Mostly when I or someone else transfers files over FTP and accidentally overwrites the .htaccess from one environment with it's counterpart from another environment, and the site breaks. Also it means I can't include .htaccess in my git repository without possibly breaking things.
From my testing, relative urls don't seem to work at all. I think maybe Apache just doesn't support relative urls in .thaccess files for Redirects and ErrorDocuments. At least that's the way it seems. I get a server error when I try.
I'd like a way to have a single .htaccess file I can share between all 3 environments and include in the git repository. If anyone knows a good way to accomplish this that would be awesome. Solutions don't have to use .htaccess, I'm open to any solution that makes my code less dependent on absolute paths or urls.
I have WordPress installed and running on GAE and have added my own custom domain via Google Apps. This is great but my appspot.com url is still publicly accessible and searchable.
How would I go about blocking this and redirecting to my custom domain?
I imagine it involves adding a url handler in the app.yaml file that points to a php file. I have no idea what would go inside though.
Also, how would I then go about setting up a 301 redirect for website canonisation and SEO that accounts for SSL and cron entries?
Any help is appreciated, thanks!
The appspot.com URL is always accessible and there is no way to turn it off. You can't do much in the app.yaml since it's not aware of the custom domain. I'm not really a PHP guy but you should do is to write manually the redirect based on the host URL if you really want to do that. Since you're using WordPress you might need to do quite some work if you don't want to redirect only from the root, but from any page.
Personally I think you should just leave it there and do nothing, even Khan Academy is not redirecting (http://khan-academy.appspot.com) and I'm pretty sure that very few are actually doing that.
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/
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