RewriteRule newbie need help!

Hai folks,

I want to rewrite below url

http://mysite.com/peoplesearch.php?FirstName=First+Name&LastName=tom&Submit=Find

to

http://mysite.com/tom.html
  • the last name parameter is always changing. for example i have put ‘tom’ in that.

Now i have done the rewriting and upload the .htaccess to my root folder. but it’s not working :rolleyes:

my .htaccess as follows.

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\\.html$ peoplesearch.php?FirstName=First+Name&LastName=$1&Submit=Find [L]

AddType x-mapp-php5 .php

Please Help !

Hi af!

OMG! You want to use tom.html as your new URI and redirect TO peoplesearch.

[COLOR="Gray"]Options +Indexes
Options +FollowSymlinks[/COLOR]
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\\.html$ peoplesearch.php?FirstName=First+Name&LastName=$1&Submit=Find [L]

[COLOR="Gray"]AddType x-mapp-php5 .php[/COLOR]

Okay, the Gray items should be in the httpd.conf, not in the .htaccess.

The RewriteBase is there to UNDO a Redirect. Where is that Redirect? If you don’t have a Redirect, get rid of that statement, too.

Okay, that leaves the RewriteRule … and I loathe the inappropriate use of “lazy regex” (the (.*)). You don’t want to redirect xyz/123.html to peoplesearch.php, do you? Do you have a list of LastNames? Will they be lowercase or upper and lowercase? Specificity is important when you’re using regex!

Regards,

DK

Hai dkline

If you’re on shared hosting, it is extremely unlikely that you’ll have access to httpd.conf, since that is the configuration file for the entire server…
i got that quote from a google search. so what i can do now is just delete those lines you pointed out in my .htaccess file. but,

AddType x-mapp-php5 .php

That is require to run my php site. if i delete that line, my php script not working.

You don’t want to redirect xyz/123.html to peoplesearch.php, do you? Do you have a list of LastNames? Will they be lowercase or upper and lowercase? Specificity is important when you’re using regex!

no i just want to rewrite that long url to just mysite.com/tom.html. there is no .html physical file in the server though. i dont have list of last names. people just visit my site and enter the last name of the person. last name is not optional. so always user have to fill that. it can be low or upper case.:slight_smile:

Edited :
i just removed this two lines and tested. the result is same.

Options +Indexes
Options +FollowSymlinks

Edited:

Removed below line also and tested. not working. url remain original. :frowning:

RewriteBase /

oh god, the way i undestanded the things about url rewrite is wrong it seems. i expected with my above .htaccess code, when sombody enters the last name and click search button in my site, i expected the resulted page url to be shown http://mysite.com/tom.html insted of http://mysite.com/peoplesearch.php?FirstName=First+Name&LastName=tom&Submit=Find in the browser address bar. this is not happning with my above code. one my friend here just pointed out that my rewriting coding is correct and working. but not the way i expected. he shown that if i execute http://mysite.com/tom.html it works fine now. so now i undestand what really happening :slight_smile:

Yes dklynn, as you pointed out, there are few unnecessary lines of code :slight_smile:

Thank you for the kind support!

af,

GOOD! NOW you understand that YOU must create the link in the format you want visitors to see them and THEN YOU create the mod_rewrite to redirect to the link that Apache can serve. The easy way to remember is that Apache can’t GUESS what you want your visitors to see - that’s YOUR job!

Regards,

DK

Cool Thanks dklynn :slight_smile: