Url mapping in php

URL mapping in PHP?

With Apache, you are able to setup URL Rewriting for your php pages with mod_rewrite, check this resources:

Solution 2

Other than using mod_rewrite, as already reported you can do a little of magic with a simple trick.

Put into the .htaccess a directive like this one

 ForceType application/x-httpd-php 

substitute ^servlet$ with a regular expression of your choice (it will be the name of your dispatcher)

The file servlet should be similar to this

The url can have the form: http://yoursite/servlet/reports/sales/2009 you can also reach the form http://yoursite/reports/sales/2009 plaiyng a little with the .htacces and the dispatcher.

This method has the advantage that mod_rewrite is not required as FilesMatch (1.3+) and ForceType (2.0+) are in the apache core

Solution 3

A trick I use is the $ _ SERVER[‘PATH_INFO’] (I think you need Apache). This gets you all of the information after the PHP file extension.

http://www.example.com/page.php/rest/url 

the $ _ SERVER[‘PATH_INFO’] will contain:

The page can then redirect, process some code or whatever based on that string.

This is good if you don’t have access to the Apache Configs or .HTACCESS, Also if things change you can make page.php a directory name for static file placement. Oh and PHP doesn’t need to have a .php extension. I’ve used .api or somesuch in the past.

http://www.example.com/worker.api/rest/url 

That seems to work well for me.

Solution 4

As others have mentioned you can use mod_rewrite to do this but also you could use a front controller design pattern which is what many of the web frameworks use. Take a look at Horde routes or Zend_Controller_Router_Rewrite which can be used for MVC,

Solution 5

This sounds like something that mod_rewrite would typically be used for (as a part of Apache, not PHP.) I have not heard of anything in PHP which would accomplish this.

URL Rewriting in php - Full Tutorial

PHP Simple Routing System

URL Parameters | PHP | Tutorial 13

1 Clean URLs With PHP -- simple urls

Hướng dẫn tự viết framework PHP - Bài 4: Routing, sử lý url với htaccess và viết cơ chế routing php

Bạn đã biết lấy dữ liệu từ URL trong Php chưa? - Unitop.vn

Lordn__n

Lordn__n

I am a software developer from Perth, Western Australia (now living in New York City) with roughly 13 years experience in developing end-to-end solutions in Java, C#, C, C++, Perl, PHP and HTML/CSS/Javascript. I have experience in developing user interfaces (Web and desktop), database design and development (Oracle, SQL Server, MySQL), data modelling, software design, data conversion, Web application development and high-performance high-availability computing. I work for Google in New York City. I have a blog I call C for Coding. Come check it out!

Updated on February 20, 2020

Comments

Lordn__n

I come from a Java background and with any servlets-based technology, it’s trivial to map a range of URLs (eg /reports/, /secure/.do) to a specified servlet. Now I’m less familiar with PHP but I haven’t yet seen anything that does quite the same thing with PHP (or mod_php). It’s entirely possible that I’m missing something simple. How do you do this in PHP? One of the reasons I want to do this is «one use» URLs. Now this can sorta be done with GET parameters (like an MD5 hash token) but I’m interested in URL mapping as a general solution to many problems. Another big reason to use something like this is to have RESTful URLs.

Источник

Url Mapping in PHP

With Apache, you are able to setup URL Rewriting for your php pages with mod_rewrite, check this resources:

  • mod_rewrite: A Beginner’s Guide to URL Rewriting
  • Module mod_rewrite
  • URL Rewriting Guide

Mapping URL into custom files

if you do want to go down the mod rewrite route adding the following to an .htaccess file in the site root should do it. You will need to make sure mod rewrite is on for XAMPP and I can’t help you there I’m afraid. As you can see it rewrites the url, not the windows filename — so it would work on any OS.

The ([a-z]*) means it will take any filename.php with lowercase letters and redirect to /view.php?p=$1 where the $1 will be replaced by filename.

the [L,R] (L means last rule so stop processing if any more are reached, and the R means redirect (it will change the url in the browser). Use P instead to reverse Proxy (the user will still see the url they requested but the server will serve the correct file) — This will require mod_proxy as well.

 
RewriteEngine On
RewriteCond % ^view/
RewriteRule ^view/([a-z]*).php$ /view.php?p=$1 [L,R]

How to Implement URL Routing in PHP

If you use Apache you can do the URL routing via mod_rewrite.

RewriteEngine On
RewriteRule ^(dir1)/?(path2)? main.php?dir=$1&path=$2

That’ll have any request like

http://yoursite.com/main.php?dir=dir1&path=path2

The other alternative have every request redirect to a single php file

RewriteEngine On
RewriteRule (.*) main.php?request=$1

and then to do it in code, where you can use a similar approach, by having a set of regular expressions that are matched by some code and then redirected via header() or just internally.

URL mapping with Azure and PHP

Well, Azure Web Apps use IIS to host your application. The best equivalent of Apache’s .htaccess system is actually using web.config file to handle URL rewrite in IIS.

For example, you can just put the following web.config file into your web app’s root folder to hide .php extension. For more info, please refer to https://www.saotn.org/iis-url-rewrite-hide-php-extension.









" matchType="IsFile" negate="true" />
" matchType="IsDirectory" negate="true" />
.php" />

REST URLs mapping and physical implementation in PHP

  1. You should redirect all of your requests to one file with htaccess+mod_rewite.
  2. Then you should parse URI with PHP.
  3. A Controller class to decide what action to execute basing on parsed parameters.

So you run showBook() action with parameter 1234 — showBook(1234) , which will do all the rest of work.

I recommend to use some simple framework for REST applications. For example Slim Framework.

Источник

Url Mapping In Php

Web Servcies in PHP web application ?, Solution 1: If your looking to convert places to mappoints though php, php print «$firstname $lastname»; ?, php /*require_once(‘header.php’);*/ ?, php /*require_once(‘footer.php’);*/ ?

Django — URL Mapping

mapping and it’s done by editing your project url.py file (myproject/url.py) ., It’s where you define the mapping between URLs and views., A mapping is a tuple in URL patterns like − from django.conf.urls import patterns, include, > The marked line maps the URL «/home» to the hello view created in myapp/view.py file., The pattern − A regexp matching the URL you want to be resolved and map.

URL pattern mapping

Question: I have a jsp whose url pattern is /data/viewableImage.jsp, Is there a way in the url pattern to have the jsp be called even if the user does not, include the .jsp part of the url?, > data /data/*

Getting Google Maps URL? 🙂

php

Grails url mapping

mapping in grails?, mappings replaced by our custom url mappings from the grails controller?, Question: what the urls mapping processing order for the, >default URL mappings: static mappings = < "/$controller/$action?/$id?", This difference is demonstrated not specifically highlighted in the Grails URL mapping

Rack URL Mapping

(:map) \ or body.respond_to?(:each) and (body = body.each).respond_to?, (:map) > Far from elegant. , How do I let through this one url with Rack::Auth::Basic?

Php redirect from url to another url php

In other words, map the URL in the browser to something else on the filesystem, transparently., don’t need the [PT] flag used there, which allows further handling of the mapped, This will handle an incoming request like domain.com/ab/1234567890 , and map, php » tag., php //your php codes //. ?> . etc.

Php php get url full path of url

p> Solution 1: You can use this simple php, php $link = (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘on’ ? «https» : «http») ., You can make a call to the PHP page with Javascript, get the result via AJAX, and then, In this example, I will feed the php a parameter that will determine what the URL will be., example the PHP code would look something like:

Источник

Читайте также:  Button handler in java
Оцените статью