We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Problem with the rewrite rule

Simon
Simon asked
on
Medium Priority
339 Views
Last Modified: 2012-08-13
Hello,

I have a following rule in the .htaccess file

RewriteEngine on
RewriteRule ^home$ main.php?mainID=1

main.php file is located in public/OKD/ folder, and .htaccess file is located in the same folder.

When I go to somewebsite.com/OKD/home I get the following error:

Not Found
The requested URL /s/o/somewebsite.com/public/OKD/main.php was not found on this server.

Any idea why this would be happening?

Thanks,
Dragan
Comment
Watch Question

CERTIFIED EXPERT

Commented:
You rewriteRule appears wrong.  Could you tell me what you want to redirect to where?
SimonIT Manager

Author

Commented:
What I want to do is when you go to somewebsite.com/OKD/home, I want it to redirect to http://somewebsite.com/OKD/main.php?mainID=1.
CERTIFIED EXPERT

Commented:
In you Apache config file (httpd.conf or apache.conf), use this redirection

Redirect /home http://somewebsite.com/OKD/main.php?mainID=1

Restart apache service

Any issues?
CERTIFIED EXPERT

Commented:
Sorry, I mixed up this one with another one.  Please hang on
CERTIFIED EXPERT

Commented:
RewriteRule /home main.php?mainID=1
SimonIT Manager

Author

Commented:
Different error now...
The requested URL /OKD/home was not found on this server.
CERTIFIED EXPERT

Commented:
Sorry, my fault.  This should work. If it doesn't, I would put more conditions in
RewriteRule /home http://somewebsite.com/OKD/main.php?mainID=1
SimonIT Manager

Author

Commented:
Yes, I know that works, but doing it that way, in the address bar, the http://somewebsite.com/OKD/main.php?mainID=1 shows then. I want it to show http://somewebsite.com/OKD/home.
CERTIFIED EXPERT

Commented:
Ok, try this one:
RewriteBase /
RewriteRule /home /OKD/main.php?mainID=1 [R,L]

SimonIT Manager

Author

Commented:
Nope... The requested URL /OKD/home was not found on this server.
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
SimonIT Manager

Author

Commented:
Still the same. The requested URL /OKD/home was not found on this server.
CERTIFIED EXPERT

Commented:
Ok.  Please give complete path.

cd OKD
pwd

Put the complete path

RewriteRule ^(/home)$ /complete/path/OKD/main.php?mainID=1 [R,L]
SimonIT Manager

Author

Commented:
OKD is located in the public folder, so the complete path is /public/OKD/OKD/main.php?mainID=1.

This didn't work either.

When I tried the following:
RewriteRule ^(home)$ /OKD/main.php?mainID=1 [R,L]

It took me to the http://somewebsite.com/OKD/main.php?mainID=1 and it showed the page correctly, but at the same time it showed the  http://somewebsite.com/OKD/main.php?mainID=1 in the address bar instead of  http://somewebsite.com/home.
IT Manager
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
I am glad it worked.  So I was just a slash off.  /home instead of home
SimonIT Manager

Author

Commented:
Yes, but also the  [R,L] at the end had to go too.
CERTIFIED EXPERT

Commented:
Yes, I have been putting [R,L].  Anyway thanks for points.
SimonIT Manager

Author

Commented:
farzanj helped me get to the solution, but none of his answers were completely correct.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.