i did a website relaunch and now i need 301 redirects to keep my page rank :)
My old website looked like this:
www.domain.com/start/
or www.domain.com/start
New Website looks like this:
www.domain.com/home.html
My Rewrite-Rule looks like this:
RewriteEngine On
RewriteRule ^start/ /home.html [R=301,L]
RewriteRule ^start /home.html [R=301,L]
without the slash it redirects to home.html fine, but with start/ it redirects to home.html/ and goes 404..
I read multiple solutions but none worked for me, so your my last hope and im in kind of a hurry, thats why i ask here.
Thank you in advance, Philipp
Use a single rewrite rule. with an optional slash denoted by \/?. Terminate the rewrite rule by a $ so that /start/foo doesn't also match.
RewriteEngine On
RewriteRule ^start\/?$ /home.html [R=301,L]
try to add backslash on second line
RewriteRule ^start\/ /home.html [R=301,L]
good luck!
Related
How can I redirect every index.html file to /
For example redirect this URL: https://www.example.com/contact/index.html to https://www.example.com/contact/
Note: I don't want to redirect to the root, I want to redirect to the same directory just remove the index.html
Thank you in advance for your time
Assuming you are using Apache the following lines in .htaccess file under the /contact folder will do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/index.html$ %{CONTEXT_PREFIX}/folder/$1/ [R=301,L]
RewriteRule ^index.html$ %{CONTEXT_PREFIX}/folder/ [R=301,L]
where folder is contact in your example.
Earlier I suggested using the following rule for a shortcut of the above two:
RewriteRule ^(.*)index.html$ %{CONTEXT_PREFIX}/folder/$1 [R=301,L]
However, this has an unwanted side-effect of redirecting say something like https://www.example.com/contact/myindex.html to https://www.example.com/contact/my
Note: Please be careful not to cause redirection "loops" like:
xxx/index.html -> xxx/ -> xxx/index.html -> xxx/ ...
How is it possible to have a url of a basic website, not include the .html at the end of a webpage?
My website is just a few pages, but I don't like having the .html in my link: www.mywebsite.com/mypage.html
If I type: www.mywebsite.com/mypage, of course, it's not found :(
I navigate around my site just using typical hyperlinks.
Probably a dumb question, but I've googled it and the stuff I find is way more complex than just html code and is usually referring to php or perl.
Thanks.
You sinply make an .htaccess file and put the following in it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
What web server software are you using? If Apache, you will likely be interested in the rewrite mod.
Something like the following:
RewriteRule ^mypage/?$ mypage.html [NC,L]
In your .htaccess file. I believe you need to enable the mod first too.
Simple solution is to change the name of your website from mypage.html to mypage
How could I achieve this?
force load extension via .htaccess ".html" after a url?
Pretty simple, but I couldn't find something a stack article on this or something similar to tweak accordingly.
If someone visits Domain.com/about I want them to land on Domain.com/about.html
Simply put I want to force all url's to load .html after the url via .htaccess.
This is to cover visitors, etc. with old links that don't have .html at the end of the url.
Does this page helps you:
https://www.garron.me/en/bits/add-html-extension-nginx-apache-htaccess.html
Or take a look here, you can find a bunch of propositions.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
I started seeing 404 errors in my logs for urls like:
http://site.example.com/foo/bar.html%23anchor
Clearly the #anchor was being encoded (probably in someone else's email that I can't control) resulting in broken links. The anchor links are not that important, but I don't want my users seeing 404 pages. I thought I could fix this with a simple rewrite, but nothing I have tried has worked and none of the SO answers I looked at worked.
The rewrite codes I tried worked perfectly in RegExr and regex101, but when I try it in my .htaccess, the bad link still results in a 404 error. I have other RewriteRules working, but I can't seem to remove the unwanted %23anchor from the end of the request.
RewriteEngine on
RewriteBase /site
## Externally redirect non-canonical domain requests to canonical domain. ###
## This rule works ###
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://site.example.com/$1 [R=301,NC,L]
## This rule doesn't work ###
RewriteRule ^(\.html)(%23)(.*)$ $1 [R=302,NE,L]
I need to change this:
http://site.example.com/foo/bar.html%23anchor
into this:
http://site.example.com/foo/bar.html
What am I missing?
You are missing everything in front of ".html". Try this rewrite:
RewriteRule ^(.*\.html)(%23)(.*)$ $1 [R=302,NE,L]
https://regex101.com/r/fV3oU3/1
Thank you for all of your suggestions, but none of them solved the initial problem. Because the RewriteBase rule affects all relative rewrites, I could not see a way to write this rule as I originally intended. In the end the only thing that seemed to work was to rewrite to an absolute path. This is the rule I ended up with. It is not flexible and only works for this page, but at least it fixes the specific broken link I am currently trying to correct:
RewriteRule ^(.*bar\.html)\x23.*$ http://site.example.com/foo/bar.html [R=302,NE,L,NC]
The above rule rewrites this: http://site.example.com/foo/bar.html%23anchor
to this: http://site.example.com/foo/bar.html
Replace your last rule with this:
RewriteRule ^(.+?\.html)\x23 /$1 [R=302,NE,L,NC]
%23 is matches by \x23 in RewriteRule.
Part One
I want to .htaccess redirect all HTML files to the home page. I looked at this guy's question (htaccess redirect all html files), and wrote this code:
RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$
RewriteRule .*\.html$ "http\:\/\/pandamonia\.us\/" [L]
but the problem is that it also redirects the homepage to itself, causing the universe to end.
So my question, is how can I redirect every HTML page that is not the homepage to the homepage.
Part Two
Exclude certain subfolders and domains in redirects
Try changing .* to .+ in the regexp, that should mean 'at least one character' instead of zero or more characters, so the empty string should be avoided.
Wait. The initial '/' is included. Try it like:
RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]