Hey all, say my site after going through a search comes up with this address: http://www.mysite.com/index.php?locate=results&city=DY&minp0&max=9&othercritera=%&moregoeshere how could I get it sent through .htaccess like with this: if I put this in .htaccess instead of http://www.mysite.com/index.php?locate=email RewriteEngine On RewriteRule ^email$ index.php?locate=email the person would only need to type: http://www.mysite.com/email Somebody please tell me how to do the same for this: http://www.mysite.com/index.php?locate=results&city=NYC&minp0&max=9&othercritera=%&moregoeshere so they'd only have to type in: http://www.mysite.com/nyc How can the PHP do this on the fly? I really dunno how to do it... fetch it from the db and write it etc - complete novice... I have a mysql db set up with the data in it already. Thanks!!!
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)$ index.php?locate=results&city=$1&minp0&max=9&othercritera=%&moregoeshere Note the $1 which is where the city name from the request (e.g. NYC) is inserted Also note that this directs all request that aren't for physically existing files and directories so in your PHP, check if "city" is a valid value and if not, send a 404 as would have been the case before the rewrite
Krt how you going mate - yeah I see your idea (being new to PHP tho) I don't know how to request_filename - oh hold on... is this standard code and the 3rd rewrite is specific to my page? What about including a state as well as a city? Would that be $2? Thanks for the post!!!
The two lines starting with RewriteCond are to make sure the rule is not applied when the user is requesting a physically existing file. To include a state as well: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?$ index.php?locate=results&city=$1&state=$3&minp0&max=9&othercritera=%&moregoeshere Note I am guessing that your index.php takes a state variable Note this accepts requests in the form example.com/city/state To do it the other way around, e.g. example.com/state/city, use: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?$ index.php?locate=results&city=$3&state=$1&minp0&max=9&othercritera=%&moregoeshere Note the switching of $3 and $1
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?$ index.php?locate=results&city=$1&state=$3&minp0&max=9&othercritera=%&moregoeshere I tried the above and when I typed in mywebsite.com/state it worked but when I typed in mywebsite.com/state/city it didnt ALSO how can I have to parsed through the php so mywebsite.com/state/city appears in the address rather than index.php?locate=results&city=$1&state=$3&minp0&max=9&othercritera=%&moregoeshere Thank you
Recall I said that if you wanted it the other way around, i.e. mywebsite.com/state/city, use the second set of code: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?$ index.php?locate=results&city=$3&state=$1&minp0&max=9&othercritera=%&moregoeshere Replace ^([^-]+)(-([^-]+))?$ with ^([^/]+)(/([^/]+))?$ if you want hyphens instead of slashes to delimit the values.
http://www.mywebsite.com/index.php?locate=viewresults&cp_county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_property_type=%25&minbeds=1&maxbeds=99[/QUOTE] I actually want it to look like http://www.mywebsite.com/LH-1-property So: what shud the rewrite be plz? RewriteRule ^([^/]+)(/([^/]+))?/?$
Thanks for that krt... its just still, when I directly type: mywebsite.com/LH/1-property it doesn't work? mywebsite.com/LH shows all the props in that county but the /1-property part doesn't
I see (you asked for LH-1-property first though ) RewriteRule ^([^/]+)(/(.+)-property)?/?$ http://www.mywebsite.com/index.php?locate=viewresults&cp_county=$1&cp_town=$3&... Format examples: mywebsite.com/LH mywebsite.com/LH/1-property
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. This is whats appearing now... I have my .htaccess file as: RewriteEngine On RewriteRule ^register$ index.php?locate=register RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/(.+)-property)?/?$http://www.mywebsite.com/cpzr/index.php?locate=viewresults&cp_ county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_property_type=%25&minbeds=1&maxbed s=99
The error was because you joined the pattern and the URL It should be: ^([^/]+)(/(.+)-property)?/?$ http://www.mywebsite.com/... not: ^([^/]+)(/(.+)-property)?/?$http://www.mywebsite.com/... Also you don't need mywebsite.com in the URL... my bad for including it before. RewriteRule ^([^/]+)(/(.+)-property)?/?$ index.php?locate=viewresults&cp_county=$1&cp_town=$3&...
Can you give me an example? I have tested my code and mywebsite.com/LH/1-property does indeed rewrite to index.php?locate=viewresults&cp_county=lh&cp_town=1
krt - I think it wasn't working because for some reason the 2nd / was making the website feel it was in a new dir and so the css file didnt work! RewriteRule ^([^/]+)(/(.+)-property)?/?$ index.php?locate=viewresults&cp_county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_pr operty_type=%25&minbeds=1&maxbeds=99 Tried this for LH-1-property but it didnt work? RewriteRule ^([^/]+)(-(.+)-property)?/?$ index.php?locate=viewresults&cp_county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_pr operty_type=%25&minbeds=1&maxbeds=99
I see, I forgetfully assume everyone else uses paths relative to root (as they should) On your site, LH/1-property is working so maybe you are using the previous rewrite rule instead of: RewriteRule ^([^-]+)(-(.+)-property)?/?$ index.php?locate=viewresults&cp_county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_property_type=%25&minbeds=1&maxbeds=99 [L] Code (markup): 2 of them are used in "not" sets, e.g. [^-], which means anything except a hyphen. If, heaven forbid, it still doesn't work, try this: RewriteRule ^([^-]+)(-(.+)-property)?/?$ index.php?locate=viewresults&cp_county=$1&cp_town=$3&minprice=0&maxprice=999999999999999&srch_property_type=%25&minbeds=1&maxbeds=99 [R=302,L] Code (markup): That way, you can see what the URL is being rewritten to in the address bar. e.g. enter ...com/LH-1-property and see what it rewrites to.
Hey krt, I changed the code to RewriteRule ^([^-]+)(-(.+)-property)?/?$ and it KIND OF worked! For some reason - this is VERY strange, the resulting pages are different? The same criteria is entered but the results are different?
Would you be okay giving me temporary FTP access so I can get this sorted out for you instead of going back and forth for possibly awhile yet? Also, regardless, did you try using [R] at the end of the RewriteRule and comparing the URLs? Another possibility is the script is not getting vars from the URL properly.