0

how to use different url structure in php ?
I want to know to handle url like this
www.example.com/10/2011
instead of
www.example.com/?m=10&y=2011

5 Answers 5

2

Maybe it will be better to do with server configuration - .htaccess (in Apache) or web.config (in IIS). Create rewrite rule from ^(\d+)/(\d+)$ to /?m=$1&y=$2. For example, in Apache it will look like:

RewriteEngine On
RewriteBase /
RewriteRule ^(\d+)/(\d+)$ /?m=$1&y=$2
Sign up to request clarification or add additional context in comments.

Comments

1

this can be achieved through apache's mod_rewrite mechanism. create a .htaccess file in your webroot with the following contents:

RewriteEngine on

RewriteRule ^([0-9]+)/([0-9]+) ?m=$1&y=$2 [NC]

similar mechanisms exist for other web servers.

Comments

0

You should use Rewrite(google it) engine in Apache or nginx. Something like this exists in ISS too.

Comments

0

This is not achieved by PHP, but by some other "component". E.g. the Apache web server has a module (the rewrite engine) that can rewrite the URL so that you can use URL like www.example.com/10/2011 and it translates them into www.example.com/?m=10&y=2011 so that in your PHP code you can use $_GET['m'] and get the month. Rewrite engine for Apache (for other webserver similar things may exist)

Comments

0

One easy method is something like this:

In your .htaccess file

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?$1 [L,QSA]

What this does it redirects everyhting to index.php if its not a physical file or dir.

Then you configure your index.php to handle this request.

Example

www.example.com/10/2011

will become $_GET['10/2011']; so you can use data in your script.

1 Comment

Obviously this is for apache. Other web servers may have different approaches

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.