• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

htaccess redirect

Hello experts,

I am trying to do something very simple using htaccess:


Redirect all the page is following :

http://www.mydomain.com/direcotry1/directory2/

TO:

http://www.mydomain.com/direcotry1/301.html

There is already an htaccess file inside the "direcotry1" folder and its the only htaccess file i can access.

Thank you. I hope to find a quick resolution.
0
Refael
Asked:
Refael
  • 7
  • 5
1 Solution
 
Jan SpringerCommented:
Make sure that you have the rewrite engine on in your apache configuration and put this in the htaccess or section of the httpd.conf for this host:

RewriteCond %{HTTP_HOST}   !^www\.mydomain\.com/direcotry1/directory2/[NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://http://www.mydomain.com/direcotry1/301.html/$1 [L,R]
0
 
RefaelAuthor Commented:
Hi  _jesper_ thank you very much

In the htaccess i have already some few lines of code will pasting this harm anything else on that domain beside this directories?
0
 
RefaelAuthor Commented:
Hi again,

I have pasted your code yet nothing is happening.
I have more codes of RewriteRule for other sub-directories so maybe that's why it does not work?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jan SpringerCommented:
It should.  Do the logs provide any information?
0
 
RefaelAuthor Commented:
It should? what do you mean? it should work or the fact i am having more code there might create a problem?

i do not understand how does line 3 in your code knows that it should refer to line 1 in your code if i have more similar lines before it.
0
 
Jan SpringerCommented:
Are you keeping the rewrite conditions with the rewrite rules that belong to them?  Are there any other rewrite rules that overlap with this?
0
 
RefaelAuthor Commented:
still does not work...

i checked. there is no code related to this directory e.g. "directory2".
your rewrite rule have this " http://http://" is this ok?

would it be better to have an htaccess inside the "directory2" folder and then redirect all the pages from there?
0
 
RefaelAuthor Commented:
this code i have found works. is it good?

RewriteRule ^directory2/(.*) http://www.domain.com/directory1/301.html [R=301,L]
0
 
Jan SpringerCommented:
No, it shoudn't have.  I apologize for the bad paste.  If corrected, does it work?
0
 
RefaelAuthor Commented:
Hi _jesper_

removing the double http did not help. but the code i found works fine, have a look above.
 
RewriteRule ^directory2/(.*) http://www.domain.com/directory1/301.html [R=301,L] 

Open in new window


is it ok to use just this code?
0
 
Jan SpringerCommented:
If it works, yes.  It will catch everything with "directory2" as a word of caution if you host multiple virtual hosts.
0
 
RefaelAuthor Commented:
Yes it should catch everything with "directory2". Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now