1

I want to change the url from

http://mywebsite/address.php?state=oh&office_id=1425

to

http://mywebsite/office/{variable inside my php page}.php

appreciate if you can help me

2 Answers 2

3

This should work:

RewriteEngine On

RewriteRule ^office/([0-9]+).php$ address.php?state=oh&office_id=$1

Which would result in:

http://expample.com/office/1425.php

Or if you'd like the state to be dynamic as well, you could do this:

RewriteEngine On

RewriteRule ^office/([a-zA-Z]+)/([0-9]+).php$ address.php?state=$1&office_id=$2

Which would result in:

http://expample.com/office/oh/1425.php
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Josh, my php variable is the office name (one word), how htaccess will show this?
+1 for the answer. Just I think the state must also be part of the URL and passed as param to the script.
Updated, hopefully it's better worded now.
Many thanks for you all, if I passed the statename to the url, what is the final htaccess line should I use
@Pipo You'd use the second one if you wanted the GET variable of state to be dynamic.
|
1

I would suggest to have a look at mod_rewrite Apache module. You can do various URL manipulations with it.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Beginner's guide:

http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Comments

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.