I am trying to redirect the main page to a blog. I am using the htcaccess code like this
Redirect / http://coolefitness.com/blog
The result is http://coolefitness.com/blogblogbloglblogblog
no idea why it is repeating the blog. I haven't told it to do that. I don't even know how I would make that loop happen.
Here is my full htcaccess
DirectoryIndex index.php
Redirect /index.html http://coolefitness.com/index.php
Redirect /members.html http://coolefitness.com/members.php
Redirect /what-is-coolefitness.html http://coolefitness.com/what-is-coolefitness.php
Redirect /instructors.html http://coolefitness.com/instructors.php
RewriteEngine On
#Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
RewriteRule ^([^/]+)/$ http:/coolefitness.com/blog/$1 [R=301,L]
Redirect / http://coolefitness.com/blog
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
ErrorDocument 500 /404.php
FallbackResource payment/app.php
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
I have tried doing a rewrite, but that isn't working. I have removed it and the issue still happens.
Related
I want to redirect the faulty links to the home page. Usually all the faulty links or links without correct path shows the 404 page but I want to redirect these kind of URLs to home page.
in routes
$route['404'] = 'home/error404';
$route['404_override'] = 'home/error404';
.htaccess
ErrorDocument 404 /404
ErrorDocument 404 https://www.safehousepg.in/404
Add the following lines in your .htaccess
ErrorDocument 404 https://www.safehousepg.in/404/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]
404.php in the last line will be your rout for redirect.
I am having problem with adding trailing slash end of URL. I have tried many suggestions from overall web but came up with no successful outcome. Hiding .html works fine, however adding slash does not really work. Main issue is that after I apply code below, the slash appears but website or any page gets never loaded. It keeps in loading mode. I would appreciate if someone helps me through.
My code in .htaccess is:
ErrorDocument 404 /thanks.html
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.html(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://%{HTTP_HOST}/$1 [R=301,L]
Whenever i add "WWW" to a page on my website, it erases some of the css of that page. but if i load the page without adding the "WWW." prefix it displays properly. Pls help
You could redirect your site to to go the non www.-site, with this redirect:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
If you add that code to your .htaccess people will get redirected to http://yourdomain.com when they enter http://www.yourdomain.com
I'm making a .htaccess for my web page, here's the code:
Options -Indexes
RewriteEngine On
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
RewriteRule ^([A-Za-z]+)/?$ $1/1/
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebpage\.at [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ /imgs/hotlinks.png [L]
RewriteCond %(REQUEST_URI) ^imgs/$ [NC]
RewriteRule / - [F]
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
The problem is, my images are not showing up in pages with rewritten URLs. Apparently, their routes are also affected by the rewriting. Simply explained: an image located at www.mywebpage.at/imgs/pic1.jpg loads on www.mywebpage.at/files.php?row=first&column=3, but when I try to enter www.mywebpage.at/first/3/ the browser looks for the image in www.mywebpage.at/first/3/imgs/pic1.jpg, and obviously fails to load it.
How can I fix this so that the routes of the images do not change, no matter from where I use them?
You can do:
RewriteCond $1 !^(imgs)
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
That will rewrite everything except the imgs folder.
Edit: Apologies, misread question.
Make your image paths absolute. E.g. relative path is:
imgs/image1.jpg
Absolute path is:
/imgs/image1.jpg
The slash at the beginning tells it to go to the very root of the site and then go to imgs, then image1.jpg.
I've just changed permalinks in my wordpress site.
And my old links were like that,
http://www.sitename.com/category/postname.html
Now new links are
http://www.sitename.com/category/postname/
I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
In the htaccess file in your document root, add these before your wordpress rules:
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
Of if you need to limit it by hosts, you can use mod_rewrite:
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
In the htaccess file, just put:
Redirect 301 /postname.html http://www.sitename.com/category/postname/
The accepted answer (above) from Jon Lin caused some issues for me.
This is my result, which works well, and is a bit more compact.
It works for both, with and without directories in the path.
Oneliner:
RedirectMatch 301 ^/(.*)\.html$ /$1
Or if you need it limited by host:
RewriteCond %{HTTP_HOST} myDomain.com [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Example: