mr_zhang Posted July 10, 2007 Share Posted July 10, 2007 Hi guys, I need simple help here with htaccess. I want to direct: http://sub.site.com/folder/index.php ==> http://sub.site.com/folder/parser.php?this_file=index http://sub.site.com/folder/faq.php ==> http://sub.site.com/folder/parser.php?this_file=faq http://sub.site.com/folder/sitemap.php ==> http://sub.site.com/folder/parser.php?this_file=sitemap I've created an .htaccess file in http://sub.site.com/folder/ that (only) contains: RewriteEngine on RewriteRule ^(.*)\.php$ parser.php?this_file=$1 When I type type the url (e.g. http://sub.site.com/folder/index.php), it reads the parser.php but not loading the correct parameter for "this_file". When I add "[R]" to the end of RewriteRule, it seems to load "parser.php?this_file=parser" instead of "parser.php?this_file=index" How to solve this? Regards, Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/ Share on other sites More sharing options...
sKunKbad Posted July 10, 2007 Share Posted July 10, 2007 you dont need to escape the . before php, and you dont need the $ after, and you should have a slash before parser, like this: RewriteRule ^(.*).php /parser.php?this_file=$1 Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-294840 Share on other sites More sharing options...
mr_zhang Posted July 11, 2007 Author Share Posted July 11, 2007 you dont need to escape the . before php, and you dont need the $ after, and you should have a slash before parser, like this: RewriteRule ^(.*).php /parser.php?this_file=$1 Thanks for the suggestion sKunKbad, however the code gives error 404 file not found. When I try to erase the "/" in front of "/parser" it reads the parser.php correctly however it still gives "parser" as the result of "this_file" parameter instead of the correct parameter. Any idea how to fix this? Regards, Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-294845 Share on other sites More sharing options...
sKunKbad Posted July 11, 2007 Share Posted July 11, 2007 Try adding: Options FollowSymLinks above RewriteEngine On and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-294847 Share on other sites More sharing options...
mr_zhang Posted July 11, 2007 Author Share Posted July 11, 2007 Hi sKunKbad, Following your suggestion I made the .htaccess into Options FollowSymLinks RewriteEngine on RewriteRule ^(.*).php /parser.php?this_file=$1 It gives error 500 Server error! The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. If you think this is a server error, please contact the webmaster. Error 500 sub.site.com Wed Jul 11 03:27:53 2007 Apache/2.0.54 (Debian GNU/Linux) mod_auth_pgsql/2.0.1 mod_ssl/2.0.54 OpenSSL/0.9.7e mod_perl/1.999.21 Perl/v5.8.4 Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-294851 Share on other sites More sharing options...
sKunKbad Posted July 11, 2007 Share Posted July 11, 2007 I don't know what to say. I know that there are definately differences in hosts, and how mod rewrite is implemented. The rewrite rule that I showed you would definately work on the server I am on. Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-294972 Share on other sites More sharing options...
hackerkts Posted July 11, 2007 Share Posted July 11, 2007 Double check your httpd.conf, make sure you had mod_rewrite.so activated. Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-295044 Share on other sites More sharing options...
mr_zhang Posted July 11, 2007 Author Share Posted July 11, 2007 I don't know what to say. I know that there are definately differences in hosts, and how mod rewrite is implemented. The rewrite rule that I showed you would definately work on the server I am on. OK, I've asked my host about this. After long "conversation" (they don't provide programming support) they said the problem is because the PHP in their server is executed via CGI. That means the "Options" directives are set automatically. Thus if I set it manually it will give error 500 (server error). Anyone know who to fix .htaccess for my problem? Quote Link to comment https://forums.phpfreaks.com/topic/59270-simple-rewrite-in-same-directory/#findComment-295518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.