Home Backend Development PHP Tutorial drupal 代码实现URL重写_php技巧

drupal 代码实现URL重写_php技巧

May 17, 2016 am 09:19 AM
drupal url rewrite

以下是实现例子:

复制代码 代码如下:

/*
* 伪地址转原地址 (url_alter)
*/
function example_url_inbound_alter(&$path, $original_path, $path_language)
{
if (preg_match('|^article(/.*)|', $path, $matches)) {
$path = 'node'. $matches[1];
}
}
/*
* 原地址转伪地址 (url_alter)
*/
function example_url_outbound_alter(&$path, &$options, $original_path)
{
if (preg_match('|^node(/.*)|', $path, $matches)) {
$path = 'article' . $matches[1];
}
}

PS: 实现hook_url_inbound_alter时不知为何会调不出实现函数,可能因为HOOK过早加载,没有把module加载完全。所以我的做法是写在URL重写模块中,例如subpath_alias
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Nginx for request redirection and URL rewriting How to use Nginx for request redirection and URL rewriting Aug 01, 2023 pm 10:45 PM

How to use Nginx for request redirection and URL rewriting

How does PHP handle URL rewriting and beautification? How does PHP handle URL rewriting and beautification? Jun 29, 2023 am 08:21 AM

How does PHP handle URL rewriting and beautification?

How to use Nginx for redirection and URL rewriting of HTTP requests How to use Nginx for redirection and URL rewriting of HTTP requests Aug 02, 2023 pm 03:57 PM

How to use Nginx for redirection and URL rewriting of HTTP requests

How to analyze Drupal configuration How to analyze Drupal configuration May 15, 2023 pm 09:22 PM

How to analyze Drupal configuration

Golang learning Web application development based on Drupal Golang learning Web application development based on Drupal Jun 24, 2023 am 11:16 AM

Golang learning Web application development based on Drupal

How to improve the performance of your Drupal website through PHP-FPM optimization How to improve the performance of your Drupal website through PHP-FPM optimization Oct 05, 2023 am 10:09 AM

How to improve the performance of your Drupal website through PHP-FPM optimization

Preventing URL Rewriting Attacks: Website Security Development Practices Preventing URL Rewriting Attacks: Website Security Development Practices Jun 30, 2023 pm 03:45 PM

Preventing URL Rewriting Attacks: Website Security Development Practices

Using routing components to implement URL rewriting and parameter parsing in PHP Using routing components to implement URL rewriting and parameter parsing in PHP Oct 15, 2023 pm 04:21 PM

Using routing components to implement URL rewriting and parameter parsing in PHP

See all articles