0

Is there a way to make this URL:

http://readme.com/read?blog=10092

look like this:

http://readme.com/read/blog/10092

Using PHP?

2
  • Read stackoverflow.com/a/16389034/1129785 Commented Jan 3, 2014 at 9:58
  • you must have a customizable apache server to do that Commented Jan 3, 2014 at 10:01

4 Answers 4

2

It is not possible via PHP itself. Even the above example (read?blog) is not a php-only solution.

PHP is a parsed file. The webserver parses a .php script and displays it to the viewer. So you have to configure your server (Apach for example) to use the correct php file for the request. The most common solution is mod_rewrite (http://httpd.apache.org/docs/current/mod/mod_rewrite.html an lots of tutorials). You will have to edit yout .httaccess file and create configuration options.

Sign up to request clarification or add additional context in comments.

2 Comments

I have also encountered some URLs that look like this: readme.com/read/blog/10092.php how would I do this?
That's a different aspect. Some search engines skip urls without an extention. In reality there is some blog.php and it recieves 10092.php as a paramerer (or it is pre-parsed by server and only 10092) so it works just like blog.php?id=10092.
1

One technique is by rewriting the url using .htaccess. Create a .htaccess (There's a dot in front of the file name!) file inside of your root folder and place the following code inside:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /blog/(.*)/ read?blog=$1

Now you can go to the same page using the url :

http://readme.com/read/blog/10092

1 Comment

What does Options +FollowSymLinks have to do with this question?
0

It looks like you need a PHP framework, like CakePHP or CodeIgniter. One of their main feature is the routine mechanism. However, you must first understand some Object-Oriented Programming in PHP.

Comments

0

Its more complicated with plain php, you have to use htaccess too. See this example:

RewriteEngine on
RewriteRule ^/read/blog/([0-9]+)$ /read?blog=$1

Url rewriting is powered by .htaccess and inside it, regular expressions. If you want to know more about regular expressions, see wikipedia: https://en.wikipedia.org/wiki/Regular_expression

2 Comments

Okay so if I do this my URL should look like this: readme.com/read/blog/10092 but how would I get 10092 from the URL? A superglobal maybe?
You can just access it like normal url parameter: $blogID = $_GET['blog']

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.