Jump to content
MakeWebGames

Recommended Posts

Posted

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]
Posted

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.

Posted

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']

Posted

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

Posted

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 :(

Posted

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]

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.   Paste as plain text instead

  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...