Cannot implement a redirect to www url - .htaccess

I am setting up a new OpenCart store but have a problem with icons not appearing when I reach the site trough the URL that does not have www at the beginning.
I did a Google search and found out that I have to set up a redirect from the non www URL to the www one by modifing the .htaccess.text in my root folder. This is where the problem occurs, I cannot seem to find the right code to enter. The following is my current redirect code.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^eparhija\.com$
RewriteRule ^(.*) http://www.eparhija.com/$1 [R=301]
I have also tried other variants of this code bud none seem to work.
Any help would be appreciated. Also if it helps my website is www.eparhija.com

Rename .htaccess.txt to just .htaccess. Apache does not recognize the file with the .txt extension

Related

How to redirect a new page (wrong URL) to another page?

I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]

301 redirect old link to new sub directory

I am trying to do a redirect in my Joomla .htaccess file
The incorrect link is:
http://nilandsplace.com/index.php/camping_eng/camping?___store=camping_eng
I am trying to get it to go to:
http://nilandsplace.com/store/index.php/camping/camping-home/?___store=camping
No mater what 301 redirect I have tried it does not work I get a 404 page not found or I get a 500 server error. It also could just go to:
http://nilandsplace.com/store/camping/
I almost got it to work by getting rid of the index.php in the link, but there are a lot of old external links in that have it with the index.php. I have tried more then 15 different ways and still can't get it without destroying my Joomla link
http://nilandsplace.com/index.php
I know the basics, the rewrite engine is on and I have been putting everything before the Joomla redirects that are many. The Joomla .htaccess is the basic one that comes with Joomla install.
Thanks James Niland
http://nilandsplace.com
You can use this rule as your very first rule in your root .htaccess:
RewriteCond %{THE_REQUEST} /camping_eng/camping\?___store=camping_eng [NC]
RewriteRule ^ /store/camping/? [R=301,L]

Mask folder in output URL

I have this website, it is my primary domain, however the folder is actually /public_html/annexation.ca. This part is fine, I have an htaccess rule in my public_html folder to deal with that, so that it shows up as annexation.ca and not annexation.ca/annexation.ca.
But I also run a forum off of that website. The problem is that the phpbb software has an auto-direct after logon, logoff and in a couple of other instances. And when it does so it generates a URL like this:
http://annexation.ca/annexation.ca/community
This is not only cosmetically disruptive, but it also impacts the comment section at the bottom of each unique page, where I have Disqus running. What I need is to add a rule to the htaccess file in the root folder that will make these redirects be automatically translated into this again:
http://annexation.ca/community/
Thanks!
Try adding this to your .htaccess
## 301 Redirect Entire Directory
Redirect 301 /annexation.ca/community(.*) /community/$1
You can try this rule on top of other rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+annexation\.ca/(community)([^\s?]+) [NC]
RewriteRule ^ /%1 [L,R=301]

htaccess multiple 301 redirects

I am looking for some help with setting up some redirect rules in my htaccess file. I have switched the site to run on Codeigniter, and basically all pages ending in .php, now just have that ending removed, ie www.mysite.com/foo/bar.php is now www.mysite.com/foo/bar
I have tried just listing the redirects like so:
Redirect 301 http://mysite.com/foo/bar.php http://mysite.com/foo/bar
Redirect 301 http://mysite.com/foo/bar/bar.php http://mysite.com/foo/bar/bar
Redirect 301 http://mysite.com/foo/bar/foo.php http://mysite.com/foo/bar/foo
etc (About 12 rules needed). Bizarrely, it works for the first rule but not the others? Am I not listing them correctly? Everything I've read tells me this is how it is to be written. So what am I doing wrong?
Additional Information that may be relevant:
My htaccess file already contains the following code (for removing 'index.php' from urls):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Not sure if it matters if this is placed before or after the rewrites? Also, the site in question is an addon domain. I am not entirely sure whether these rewrites should be placed in the .htaccess file in the public folder of the master site, or in the addon domain's subdirectory? (I've tried both, with the same result).
Help please! Thanks in advance.
Sorry, I've just solved this. I removed the base URL from each rule and now it works. ie:
Redirect 301 /foo/bar.php /foo/bar
Instead of:
Redirect 301 http://mysite.com/foo/bar.php http://mysite.com/foo/bar
Not entrirely sure why... need to read up.

url redirecting through htaccess

i have hosted two sites on same server and i mange them giving folders for each domain. i want to site comes as
example.com/example
example1.com/example1
i want to come
example.com and example.com
i come to know that htaccess url redirecting can do this but i have less idea about it.
if there is some tutorial on php regular expression please let me know.
some help is appreciable.
edited
i solved this problem by putting .htaccess file in root and writing:
RewriteEngine On
#for example.com
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/example/.*$
RewriteRule ^(.*)$ /example/$1 [L]
when i hit example.com it works fine now. it access the folder /example. but i had a problem on a certain domain. i m using codeigniter and i have to redirect its request also so that it does not show
example.com/example/index.php/controller/
i want to show this:
example.com/controller/
hope some experts can help.
The .htaccess url redirecting is setup as a file in your main directory and your code can look something like this:
# These redirects should do the trick :-)
Redirect example.com/example http://www.example.com
Redirect example.com/example1 http://www.example.com

Resources