drupal 代码实现URL重写_php技巧
以下是实现例子:
/*
* 伪地址转原地址 (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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use Nginx for request redirection and URL rewriting. As a high-performance web server and reverse proxy server, Nginx, in addition to providing basic request processing, can also use its powerful redirection and URL rewriting functions to process requests. further processing. This article will introduce how to use Nginx for request redirection and URL rewriting, with code examples. Request redirection Request redirection refers to redirecting the request to another URL after receiving the client request. Nginx provides two ways to implement

PHP is a scripting language widely used in web development, and it handles the needs of URL rewriting and beautification well. URL rewriting and beautification is a technique that changes the URL of a website to make it more readable and user-friendly, improving user experience and search engine optimization. URL rewriting is mainly achieved by modifying the website's server configuration file (such as the .htaccess file of the Apache server). Then use some functions and features in PHP to map the rewritten URL with the original URL. UR

How to use Nginx for HTTP request redirection and URL rewriting Nginx is a high-performance web server and reverse proxy server. It also provides powerful features to manage HTTP request redirection and URL rewriting. In this article, we will introduce how to use Nginx configuration files to implement these functions and provide code examples to help readers better understand. HTTP request redirection HTTP request redirection refers to redirecting a request from one URL to another URL. This is very emotional

In the process of improving website user experience, optimizing page loading speed is a crucial part. Removing index.php from the web link can make the website link simpler and more beautiful, and it is also beneficial to search engine optimization and user experience improvement. Next, we will explain in detail how to remove index.php from the DZ (Discuz) forum homepage through code, thereby improving user experience. First of all, we need to make it clear that Discuz is a very well-known forum software. The website link contains i by default.

How to Improve Drupal Website Performance with PHP-FPM Optimization Summary: Drupal is a powerful content management system, but performance bottlenecks can occur when handling a large number of requests. This article will introduce how to use PHP-FPM to optimize the performance of Drupal websites, including adjusting the configuration parameters of PHP-FPM, using the process manager, and using cache, etc., and also give specific code examples. Adjust the configuration parameters of PHP-FPM to increase the maximum number of processes and requests of PHP-FPM

Using routing components in PHP to implement URL rewriting and parameter parsing When using PHP to develop websites, URL routing is a very important function. Through URL rewriting and parameter parsing, we can convert originally complex URLs into concise and friendly URL forms, improving user experience and search engine optimization. 1. URL rewriting URL rewriting refers to converting URLs that originally contain dynamic parameters into static, easy-to-understand URL forms. The function of URL rewriting can be implemented using routing components. First, we need a route

Drupal configuration Drupal is an open source PHP content management system with a fairly complex architecture. It also has a strong security model. Thanks to the contributions and maintenance of developers in the community, there is a lot of detailed documentation and methods for strengthening the security configuration of Drupal websites. Remember, Drupal is required to run your website. To protect the entire system from hackers, we need to deal with the entire system. It includes some common server settings, configuration of web servers, PHP and databases. Additionally, any other services on the server need to be configured correctly. It provides tips and key points that can help server and website administrators audit the security of their entire system. We should understand that creating an absolute

In today's digital age, website security issues are becoming increasingly important. Among them, URL rewriting attacks are widely used in the process of hacking and data leakage. URL rewriting attacks refer to hackers taking advantage of website vulnerabilities to modify URLs to obtain unauthorized information or steal users' sensitive data. To prevent URL rewriting attacks, developers need to adopt a series of secure development practices. This article will introduce some common URL rewriting attack methods and provide some recommended preventive measures. First, let’s understand some common URL rewriting attacks
