Problem with the rewrite rule

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
cP6uHIT ManagerAsked:
Who is Participating?
 
cP6uHConnect With a Mentor IT ManagerAuthor Commented:
All right, I got it working...

The correct line is

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

Thanks a lot for your help!
0
 
farzanjCommented:
You rewriteRule appears wrong.  Could you tell me what you want to redirect to where?
0
 
cP6uHIT ManagerAuthor 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.
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.

 
farzanjCommented:
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?
0
 
farzanjCommented:
Sorry, I mixed up this one with another one.  Please hang on
0
 
farzanjCommented:
RewriteRule /home main.php?mainID=1
0
 
cP6uHIT ManagerAuthor Commented:
Different error now...
The requested URL /OKD/home was not found on this server.
0
 
farzanjCommented:
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
0
 
cP6uHIT ManagerAuthor 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.
0
 
farzanjCommented:
Ok, try this one:
RewriteBase /
RewriteRule /home /OKD/main.php?mainID=1 [R,L]

0
 
cP6uHIT ManagerAuthor Commented:
Nope... The requested URL /OKD/home was not found on this server.
0
 
farzanjConnect With a Mentor Commented:
Lets try this one
RewriteRule ^(/home)$ /OKD/main.php?mainID=1 [R,L]
0
 
cP6uHIT ManagerAuthor Commented:
Still the same. The requested URL /OKD/home was not found on this server.
0
 
farzanjCommented:
Ok.  Please give complete path.

cd OKD
pwd

Put the complete path

RewriteRule ^(/home)$ /complete/path/OKD/main.php?mainID=1 [R,L]
0
 
cP6uHIT ManagerAuthor 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.
0
 
farzanjCommented:
I am glad it worked.  So I was just a slash off.  /home instead of home
0
 
cP6uHIT ManagerAuthor Commented:
Yes, but also the  [R,L] at the end had to go too.
0
 
farzanjCommented:
Yes, I have been putting [R,L].  Anyway thanks for points.
0
 
cP6uHIT ManagerAuthor Commented:
farzanj helped me get to the solution, but none of his answers were completely correct.
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.

All Courses

From novice to tech pro — start learning today.