POG1 Posted February 21, 2009 Share Posted February 21, 2009 Apache is a tricky one! I have read a lot on this and i am still stumped. I can write some simple rewrite expressions but i am stuck still. What i have you put in the page but it will only be a single directory url. This is the code i have. RewriteEngine on #RewriteRule ^/([A-Za-z0-9-]+)/?$ index.php?page=$1 [L] That code will allow me to have URLs such as /armybase?page=buyTanks&buy=2 But how could i have a totally friendly url? With a URL like this; /armybase.php?page=buyTanks&buy=2 I want to change it to something like this; /armybase/buy-tanks/2 The website will have about 12 main pages, would there be an easy way to add all these? :S I have found this code from a social networking engine, it has nice URLs but the code is foreign to me. RewriteEngine On RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>file/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>install/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>design/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>plugins/.* RewriteRule ^index.php(/.*)$ <%SUBFOLDER%>index.php?do=$1 [L] RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>file/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>install/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>design/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>plugins/.* RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>index.php RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>robots.txt RewriteCond %{REQUEST_URI} !^<%SUBFOLDER%>favicon.ico RewriteRule ^(.*)$ <%SUBFOLDER%>index.php?do=/$1 [L] Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted February 23, 2009 Share Posted February 23, 2009 Re: Apache is hard! Why use Apache rewrite rules instead of the PATH_INFO in the $_SERVER variable? a path like /yourphp.php/army/buy would run your yourphp.php file and you would get the /army/buy string in the $_SERVER["PATH_INFO"] variable. Quote Link to comment Share on other sites More sharing options...
Decepti0n Posted February 23, 2009 Share Posted February 23, 2009 Re: Apache is hard! Yeah, don't bother with a whole lot of rules, either use the method above or if you still don't want the yourphp.php part, just send every url to a main page, and explode() the $_SERVER['REQUEST_URI'] Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 23, 2009 Author Share Posted February 23, 2009 Re: Apache is hard! Thanks for that, i didn't think of that method :D Also, what is a phtml file lol Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted February 23, 2009 Share Posted February 23, 2009 Re: Apache is hard! php html i suppose. And then contained in the file. <script language="php"> what ever php script you would like to run here </script> Do you know that the above script can actualy be harmfull to a website that allow's html input? xD Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 23, 2009 Author Share Posted February 23, 2009 Re: Apache is hard! Would this apache work correctly? RewriteRule ^/([a-z0-9/]+)?$ index.php?page=$1 [L] Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted February 24, 2009 Share Posted February 24, 2009 Re: Apache is hard! The script bit. Try it on a simple html file. <script language="php"> Do php scripting here </script> And if any site allow's html input's they best be aware. Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 24, 2009 Author Share Posted February 24, 2009 Re: Apache is hard! I have worked out a way to for it to work. RewriteRule ([a-zA-Z0-9]+)/([a-zA-Z0-9/]+) $1.php?page=$2 [L] However, there is one problem. My images and CSS wont show now :( Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted February 24, 2009 Share Posted February 24, 2009 Re: Apache is hard! I read some where. That you going to need to make your image's url like game/armybase. BTW. Is that bit from the bit i showed you could help? Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 24, 2009 Author Share Posted February 24, 2009 Re: Apache is hard! I typed it in from scratch and it worked, but didn't get any style :( There must be a better way! Quote Link to comment Share on other sites More sharing options...
mikemastah Posted February 25, 2009 Share Posted February 25, 2009 Re: Apache is hard! You could use the <base> element. <base href="http://www.yoursite.com" /> and when you the following path: "images/image1.png" it goes to http://www.yoursite.com/images/image1.png +about the rewrite stuff these are examples I use: RewriteRule ^bank/([^/]*)$ /bank.php?error=$1 [NC] RewriteRule ^train/([^/]*)$ /train.php?error=$1 [NC] RewriteRule ^mail/([^/]*)/([^/]*)/([^/]*)$ /mail.php?action=$1&ID=$2&subject=$3 [NC] Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted February 25, 2009 Share Posted February 25, 2009 Re: Apache is hard! Pog1, i told you how to do it. should do it. Contact me on msn, i'll give you the link. Quote Link to comment 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.