Copy Website to new Directory - .htaccess

I have a rather large website that I need to move to a different directory. Right now, the website has a normal structure.
www.technology.com
The company wants the entire website moved so the new main URL will be:
www.technology.com/structure
So, the current page structure which is:
www.technology.com
www.technology.com/about
www.technology.com/services
www.technolgy.com/products
needs to become:
www.technology.com/structure
www.technology.com/structure/about
www.technology.com/structure/services
www.technolgy.com/structure/products
This is an older website that isn't inside of a CMS. Would the easiest way to do this be to actually just create a directory in the root called structure and copy everything into it?
What would I do as far as catching any people that might have links bookmarked? So, if someone were to come to www.technology.com, I would want them to automatically be redirected to > www.technology.com/structure and vice-versa with everything else. I'm assuming this could be accomplished with the .htaccess file.
Any help would be appreciated.

Yes this is right just move your complete website to www.technology.com/structure and put this in to your .htaccess file in www.technology.com/
RewriteCond %{REQUEST_URI} !^/?structure(/.*)?$ [NC]
RewriteRule ^/?(.*)$ /structure/$1 [R=301,L]
One remark: The whole thing would only work if on your apache server mod_rewrite is enabled and you are allowed to use htaccess files (with mod_rewrite), this is not always the case by default.

Related

.htaccess to remove the need for adding .html in the address bar versus creating new folders for all pages

I'm sure that with any effort I could figure out how to make this work inside of a .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
But, would that be more or less efficient than just creating a folder with new index.html in each folder?
For me, the real end result that I'm trying to achieve is to not require somebody to type:
skypodstudios.com/solar.html
I would rather let it be good enough to just type:
skypodstudios.com/solar
Both seem to accomplish it, I'm just wondering which is more efficient or if either are frowned upon?
Using folders instead of files is a bad practice. You don't need a folder for each html file you create and it will only invite clutter. Using the .htaccess solution you specified is also not optimal since it will force you to put all your html files in one folder (and will not be useful if you use other file types).
I suggest you use one of the following instead:
For a small project with few files, include HTML files depending on the URI segment. You do that by telling your .htaccess to pass all url queries to your index file (usually index.php) and then that file breaks down the URL segments and retrieve the correct file from the correct folder.
For a big project with hundreds of files, ask yourself if you are using the same template (file structure) over and over again. If your project is a blog or a store chances are the answer is yes. If it is then instead of including files you'd better store your data in a database and then retrieve the current page's data via your index.php file using a database query.

htaccess removing index.php and search queries from URL

I have a site that, for a certain php function to work, needs the url to be:
/topic/index.php?height=###
I would like the URL to read
/topic/
What can I put in the .htaccess file to achieve this? Can I put one htaccess file in the root, or would I need to put one in each /topic/ directory?
I think the following might work for your issue:
RewriteRule ^([^/]*)/?$ $1/index.php?height=###
Of course, that's assuming a static number. If you need a dynamic number or one provided by the client, you're going to need something like:
RewriteRule ^([^/]*)/(\d+)/?$ $1/index.php?height=$2

Htaccess Image redirect to specific resize directory

Hopefully someone here can point me in the right direction as htaccess is driving me crazy at the moment.
What i am trying to achieve is an automatic redirect for certain images
Currently I use jquery to replace the image src.
The reason for this is the new resized images are in a different directory.
The problem with this method is every time we refresh we have to wait for the dom to fully load.
And I see this is possible with htaccess.
Redirect /my-domain.com/images/image1.png /my-domain.com/images/resized/image1.png
Currently this works, but for over 100 images I really need to find a dynamic solution for this
I tried the following which obviously failed.
RewriteRule ^/my-domain.com/images/(.*) /my-domain.com/images/resized/(.*) [R=301,L]
the resized directory has several directory's so the rule needs to apply to all child directories.
Although it's not a big problem to list all the directories as long as I don't list all images.
hopefully I am missing something simple here, also I wanted to make sure the redirect will not effect SEO?
maybe there is an alternative solution with htaccess?
This is a bit of a messy way to handle images - across multiple folders - but, if that's how you want to manage it, fair enough.
From the above, I understand that:
There are some images within the /images/resized/ folder
There are also some images within subfolders of the same
You want to be able to call a URL within the /images/ folder and have it transcribed to the /images/resize/ folder (with the same end)
In the webroot's .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/images/
RewriteCond %{REQUEST_URI} !^/images/resized/
RewriteRule ^images/(.+)$ /images/resized/$1
Tested OK with this htaccess tester.
"I wanted to make sure the redirect will not effect SEO?"
Filenames are not as important for SEO as alt tags and titles. There should be no change to the SEO stance of your site as a result of this change.

Issues when creating pretty URL that uses actual site urls

I want to create functionality similar to the site downforeveryoneorjustme.com. They use a pretty URL to take in the URL of any given site. I sure they use htaccess to do this, however the method i'm using is encountering problems.
This is my .htaccess file that I'm using to send the site URL to a file.php:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)?$ /file.php?var=$1
However when I type in something like
mysite.com/http://google.com the variable it sends the file is http:/google.com (missing a slash). I can't figure out why this is occurring.
Also, when I type in something like mysite.com/existingfolder, where existingfolder is a folder on my site, it always works incorrectly. The variable it passes to the file is missing.html instead of existingfolder. In this case, the file doesn't display images. The image can't be found, and i'm assuming its because it's searching for the image in an incorrect folder on the site. That it might think it's in existingfolder and not in the normal folder it should be in.
Does anyone know why I'm getting these problems? I'm knew to htaccess, and I'm assuming it has something to do with that.
Thanks for any help.
I sure they use htaccess to do this
I'm not. I'm not even sure they're using Apache.
mod_rewrite is not always the answer to all URL-processing problems. It's certainly prone to some of the quirks of path-based URL handling, including the removal of double-slashes.
I suggest reading the Apache-specific REQUEST_URI variable from your script, rather than relying on rewrites to get a parameter. This will give you the path requested by the browser without any processing.

.htaccess redirect all files in one folder to exact same in another folder

We simply have to move every page inside of a directory called "Music" to a directory called "Information"... That's the only change. There's lots of links to pages music and we don't want to break them all. I'm not great at rewrite conditions....
Basically, all I want to do is when a user types in music/index.php, for example, or music/life/mypage.php, to simply redirect it to information/index.php or information/life/mypage.php... just change from music to information. And I do want the correct URL (information) to show in the URL box.
...I'm pretty exasperated. I've been trying to get this thing all darn afternoon!
Use backreferences for this one:
RewriteRule ^foo/(.*)$ bar/$1
RedirectMatch ^/foo/bar/(.*) http://www.wherever.org/a/foo/bar/$1

Resources