I have a situation as follows:
I have a website with lots of files in it (Yii Framework). I need to migrate it from http://domain1.com to http://domain2.com/foo/bar/
But previous developer has put the href, src, background-image etc links as follows:
href="/assets/img/img1.jpg"
src="/assets/js/script.js"
When I open the new website in browser, all the resources should be loaded like this http://domain2.com/foo/bar/assets/... to make it work. But, browser is interpreting the resources url as http://domain2.com/assets/...
As the resources doesn't exists here, they aren't loading.
As the urls are scattered everywhere in lots of files, it's not the best idea to change each and every url.
Is there a way to change the base url through htaccess (or some other method) so that server or browser will interpret href="/assets/..." as http://domain2.com/foo/bar/assets/...
You may use this 301 redirect rule at the top of other rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain1\.com$ [NC]
RewriteRule ^assets/.+ http://domain2.com/foo/bar%{REQUEST_URI} [L,NC,NE,R=301]
This may be a dumb question, but after I load my webpages through GoDaddy's cPanel, every page won't work unless it has a .html at the end of it. Am I doing something wrong when I'm uploading it? It doesn't seem normal to need .html at the end of every page.
The files are probably written in HTML which is the most common. So if you are making new windows you must add .html at the back so the browser knows it needs to read html code and not something else. So if you were to make an "about us" page you need to save it as about-us.html
I might not have asked the question as clearly as I should. I ended up figuring out the answer regarding removing the .html from the webpage url.
Create a file called .htaccess in the root directory and add this code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
And then all the links on your site should look like this:
<a href="/portfolio">
My website had been hacked and lots of pages had been added and these have been indexed by Google. This has seriously affected the amount of traffic my site is receiving.
These pages all are all named along the lines of - '?mulberry-948.html' just with a different number for each.
I have deleted all these pages but there are back links to these from lots of websites around the web so Google is still looking for them.
Is it possible to redirect all of these pages use .htacess in a simple way without having to add a redirect for each file.
i.e can i say for anything that begins with '?mulberry' to be redirected to index.html?
Thanks
can i say for anything that begins with '?mulberry' to be redirected to index.html?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^mulberry [NC]
RewriteRule ^ /? [L,R=301]
? in the end will strip off any existing query string.
This is normal question, but i am very weak regarding .htaccess
I have one website in html.All Pages are in .html. Now only enquiry page is enquiry.php
So I want enquiry page from enquiry.php to enquiry.html in URL.
It should not affect other html files
Pls help
Provided you've already turned "RewriteEngine On" your rule might looks something like this:
RewriteRule ^enquiry.html$ /enquiry.php [QSA,L]
However depending upon your web host, that may not work out of the gate. For example, you might need to add a slash before the .html so it would read:
RewriteRule ^enquiry\.html$ /enquiry.php [QSA,L]
I've also seen where you may need to add "Options FollowSymLinks" to the top of the .htaccess file.
Ok, maybe a pretty dumb question but I can't find an answer on Google.
I am coding my site by hand. How do I make the index.html disappear from the url's? Do I use a piece of code in my html? Do I have to change my href's in my files?
Hope you guys can help!
EDIT:
I've tried this with a .htaccess file
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
It does work, but all my links aren't working anymore. I discovered I had to remove all the index.html from the href's in my documents. But that would be a lot of work. Is there an other code for .htaccess that just hides index.html?
A SIMPLE WAY TO DO THIS in Html:
(example in my case is a simple dual language site)
If your link looks like this:
Homepage
You should change it to this:
Homepage
If trying to link to another folder in your directory, like is my example:
English language
You should change it to this:
English language
Notice that "/" goes back to your root directory and automatically selects index.html, so that is why I used "en" for the English language site, because the name of the folder in that case is "en". You should also make sure that you have index.html in your English language folder, and not index-en.html.
Apache has .htaccess files and mod_rewrite,
In your .htaccess file, set:
DirectoryIndex index.html
You can also set this up in the Apache site config files too
You can specify a list of filenames, so if it doesn't find the first it moves to the next.
IIS has .config files
mod_rewrite module is responsible for all the rewriteEngine. Check on your server whether is module is present and enable.
You need to create a file called '.htaccess' in the root directory of your site containing the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
And then make sure all the links on your site don't contain '.html' at the end, e.g.:
<a href="/Home.html">
should be replaced with:
<a href="/Home">
Hope this helps!
if you dont find .htaccess, you just need to create a new file using your text editor the same way you would any other html or css file, but save it as simply '.htaccess'
And save it into the root directory, so the same folder that you have your index.html file.
I think this is configured in IIS when you deploy the site, I'm not to sure on it but I'm sure you can specify a start point that your URL will use when you just enter the UL, that implies the Index.html page.
Sorry I'm not too helpful here, hopefully it will point you in the right direction.
Often these things such as Apache or IIS have this set up already, and it looks for the Index.html, Index.php first when you just put your URL in.
Great SEO idea! This is similar to nginx redirect loop, remove index.php from url and Apache .htaccess to hide both .php and .html extentions, as well as mod_rewrite not working htaccess — the idea here, for both Apache's mod_rewrite and nginx ngx_http_rewrite, depends on the differences between the external and internal URLs — in order for the redirect from /index.html to / work, yet not cause redirect loops when actually serving index.html, you gotta make sure you only issue the redirect for external index.html requests, but never for internal ones; this can only be accomplished by looking into the actual request_uri.
Here's the code for nginx ngx_mod_rewrite:
index index.html index.txt;
if ($request_uri ~ "^(.*/)index\.(html|txt)$") { return 301 $1; }
On Apache's mod_rewrite, it'll be something like the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/index\.html$
RewriteRule ^(.*/)index.html$ $1 [R,L]
Related:
nginx redirect loop, remove index.php from url
Apache .htaccess to hide both .php and .html extentions
mod_rewrite not working htaccess
References:
http://nginx.org/r/index
http://nginx.org/r/if
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteCond
Change the link that goes to your homepage to the website address.
You may have:
Link Here
Change that to:
Link
Or try this
Simply don't type the index.html in your browser and don't advertise it as such.
You can set the 'default document' on the web server (whichever you happen to be using) to serve 'index.html' in the absence of a file part. This way, someone going to http://www.mysite.com would be served http://www.mysite.com/index.html