.htaccess help

Posted By: vijay_jimworld ()
Posted On: 2005-Oct-10 13:50

Hi Friends,
I am making a PHP site and want it to be SEO friendly also. I am stuck at .htaccess rewrite and have already wasted many hours. What I want is
http://www.mysite/1.html to redirect to http://www.mysite/abc.php?id=1

and

http://www.mysite/place/name.html to redirect to http://www.mysite/place/abc.php?id=name

Can you guys please help me how I go about this code.

Thanks



Posted By: lizardz ()
Posted On: 2005-Oct-10 19:53

RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]
RewriteRule ^place/([a-z-]*).html /place/abc.php?id=$1 [QSA,L]

([0-9]+) will allow any digit, and only any digit, 1 or more.
([a-z-]*) will allow any combination of lower case letters, plus - if you are using that for word separation, 0 or more instances. If you want it to support upper case too, make it:
([a-zA-Z-]*)

[QSA,L] will append this to your internal scripting query string, and make it the Last rewrite rule executed.



Posted By: vijay_jimworld ()
Posted On: 2005-Oct-12 08:26

Thanks Friend,
That was a perfect code with perfect explanation. It cannot be better than this. This is the best part of this forum, you will always find genius people to help you in solving your problem.






Posted By: g1smd (Staff)
Posted On: 2005-Oct-12 11:45

This rewrite stuff always gets me too; lizardz I think I'll have a job for you in a week or two...


Posted By: dirty_shame ()
Posted On: 2005-Oct-14 06:43

As a sideline, the following is SE friendly nowadays --
http://www.mysite/abc.php/1 --
Then you just parse the URL to retrieve content vars like:

$URLvars = explode("/",$_SERVER[REQUEST_URI]);
$ContentVar = $URLvars[2];

If you're worried about smooth transitions you can always throw a .304 into your .htaccess file if necessary. At any rate, whether you decide to use ReWrite and regex or the method I mentioned, Google, Yahoo and MSN will index them all equally well.


Posted By: vijay_jimworld ()
Posted On: 2005-Oct-14 09:49

Hi lizardz,
The code given by you is working fine. But if my url contains bracket or dot. Then it is not being redirected to my php page.

Example :
www.mysite/folder/abc-(xyz).htm OR
www.mysite/folder/abc.xyz.htm

are not working. Where abc and xyz are keywords in page name.

I tried some changes in .htaccess, but could not get through. If you can sugest something, I am sure you can

Thanks


Posted By: lizardz ()
Posted On: 2005-Oct-14 18:48

You have to escape special characters.

I would strongly recommend against using ( ) in urls, that's a bad idea.

however, if you want to follow through on using bad ideas, here's how you do, more or less, this is not tested, I assume it works, but as I said, it's a bad idea, so I would never actually use that:

([a-z-\.\(\)])

the \ escapes the character it precedes. dots and () are special characters in regular expressions, at least dots are, I'm not positive about (), if it works escaped, they are, if it doesn't, remove the \ from the () and try it.


Posted By: dirty_shame ()
Posted On: 2005-Oct-18 08:33

Lizardz,

Why don't they just make you the Moderator for this particular forum. You obviously have the talent and the knowledge. I've been in here from Jim's beginning. Where's the hangup? Hell, they now have children with no experience or success on the Internet at all moderating the less-taxing threads.


Posted By: lizardz ()
Posted On: 2005-Oct-18 08:50

I'm not polite enough, I have close to zero patience for the new breed of lazy script kiddies who just want to download some stupid script that will run, without learning anything about anything. I have close to zero patience for dreamweaver types who ask how to get a plugin that will let them do programming. The Jimworld php forums seem to attract an unpleasantly high percentage of those, I guess they're scared to post in more hard core programming forums or something, not sure what it is.

That would be my guess anyway, LOL... I'm also not really a php guru, I use it a lot, but I have a lot of weak spots, it's just a tool for me, although I have to admit to standing in some awe of the difficulty of doing mod_rewrite, there is nothing more difficult I've ever come across in programming.

Oh, and I'm almost pathologically incapable of being polite to ASP programmers etc, I have nothing but scorn for closed source junk, shouldn't appear here but it does now and then as an asp type pops their head in, I don't post in asp forums, I don't know why some guys insist on posting in php ones.

Plus the number of interesting questions in this particular forum comes out to about 5 a year or so, like that sendmail one recently, that really stood out for being actually informative and useful. But aside from those exceptions, these forums just don't seem to get many actual programmers as a rule, they mostly go elsewhere.

Besides, it's not like I need to moderate more forums, having to always be polite, I don't know, it's a drag, sometimes it's fine, but sometimes a stupid question is just a stupid question, and a lazy person is just a lazy person, or I'm just not in the mood that day.

Now if there were forum TOS that required code samples for any posting, that would be a different story, then you could just refer all the script/dreamweaver kids to their own forums, and focus on actually interesting questions, that's the way to go, that's how webmasterworld apache forums run, you can't just post like this guy did, jd isn't going to write your code for you.

Plus the d##ned programming on these forums... grrr... it's messed up.


[ Message was edited by: lizardz 10/18/2005 01:19 am ]




Posted By: dirty_shame ()
Posted On: 2005-Oct-18 09:43

I don't use acronyms, but I relly had to laugh (hilariously) at myself regarding your comment, no matter if I'm breaking up the thead on the original question itself. Everybody has to get a little bit smarter, somehow, on their own. Information's there for the inquisitor...

Alpha testing I guess.

Ran into some MS pwople in Seattle about a month ago. Good folks until they have the third glass of imorted wine, and then the old BigBlue, ride-for-the-brand mentality kicks in and they all start bragging about their accomplishments.

That's alright. They just think C# and .asp are God's gift to the entire Internet. That's alright too, but they make a weak case because they are completely isolated from genuine PERFORMANCE. Great mythology. Let them make the BMW payments next year.

PHP isn't about anything specifically political or corporate. It's just about people like you and me trying to deliver quality content to other people wordwide. That's it.

In short, I understand. Thanks for answering my question. I think (given that the original intent of these forums is to acually help people) that my response will be viewed with sceptisism and distain by some and relief by others, but regardless, PHP is a very strong markup language with huge benefits. Otherwise, nobody would be reading this.








Posted By: lizardz ()
Posted On: 2005-Oct-18 21:24

Hey, I studied ASP in school, I didn't know sh#t about sh#t, but I was the top student in my classes. But even while not knowing anything about anything, there was something that really really bothered me about asp, about vb6, all these languages. And the first time I saw php, and then began reading about it [keep in mind, I had zero, I mean zero, preconceived notions about any of this, this was a strict aesthetic, emotional thing, how the language felt that is], I realized that php was written by a real guy, lerdorf, and I can email him if I have anything worth telling him, and he'll email me back, if my question wasn't too stupid.

And my very first program I wrote in php, suddenly all the things I'd wanted without knowing I wanted them were there, because php is written by people like me for people like me. Asp is written for people who want to extract money from corporations in exchange for using a really vile product.

This feedback loop means that php is built by and for web developers. asp is built by and for corporations, and the developors are just disposable pawns in that game. This is why I have nothing but scorn for MS programmers, it's my belief that a good programmer would never choose to use an ms language except for one single reason: money. Of any type, I've also spent some time in the redmond campus, I've seen the bs they play first hand, and it's not pretty, and it's definitely deeply mired in that accept the rules of the game in exchange for large paychecks. And just as an add on, in each and every exchange with asp programmers, their one and final comeback is always the same: good, I'll be making the money, ha ha. That's because asp etc is so ridiculously vile that they have to pay you a lot to use it, I wouldn't touch asp programming for under $150 an hour, and I wouldn't install IIS on my main development box for any reason.

<added> See? I really am pathologically incapable of being polite around the subject of asp or ms programming junk in general.

However, I keep that to php etc forums, I realize that there's a lot of people out there who are forced to work on asp/iis platforms because that's what the clients insist on using, so I try not to get too abusive about that question in more general forums, except when it comes to trying to run a shared hosting site on IIS....

Microsoft has always loathed two things: open standards, and the internet. Once you understand that, you understand why their web related stuff totally sucks. PHP, apache, perl, mysql, these are developed directly on the web, the people who work on those work through the web, they love the web, it's their connection to the world and their projects. MS people however work on closed proprietary networks, their stuff is not public, it does not rely on the web, although sometimes they will use the web to log onto the proprietary development systems in MS, but they are just using it as a channel.

The good part of this is that ms simply does not get the whole idea of open source, open sharing of ideas, open development, they can't, they are locked into the controlled corporate networking model, it's all about control, no freedom, top down dication from bill and the other top guys, it's not open, it's not a good environment for creativity [that's why ms for example spends billions on new os systems, most of which are failing, while say mac is spending I believe something like 15 million a year on os x development, mac gets the smart creative guys, ms gets the smart greedy guys who want the fat checks]

[ Message was edited by: lizardz 10/18/2005 01:35 pm ]