Jump to content

Simple rewrite in same directory?


mr_zhang

Recommended Posts

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,

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.