比较大的项目 要不要把url都统一到一个表里面?大家都是怎么做的?
<code>是这样的,最近项目越来越大 包括 手机端 微信嵌入网站 支付宝服务窗嵌入网站 PC端(下面有很多二级域名 比如 passport api service) 等等 我在考虑 是不是要把整站的url 路径 都写入到一个表里面 然后用统一的一个函数 来调用url 否则的话 比如说 http:xxx/article 这个详细页面 url 站内各个模块都有关联 如果这个url更改了 那么代码里面 很多关于这个页面的 url 定向 都要修改 我在考虑是不是 把所有的url (包括 后台和前台) 都集中到一个表 里面 管理 然后每个url 对应有 权限 别名 rewrite 等等属性 这样 调用的时候 比如说这个 geturl("article") 根据article这个别名 来调用 url 不管url怎么改变 还是 做了 rewrite 都不用改代码了 不知道各位大神是怎么做的呢? </code>
回复内容:
<code>是这样的,最近项目越来越大 包括 手机端 微信嵌入网站 支付宝服务窗嵌入网站 PC端(下面有很多二级域名 比如 passport api service) 等等 我在考虑 是不是要把整站的url 路径 都写入到一个表里面 然后用统一的一个函数 来调用url 否则的话 比如说 http:xxx/article 这个详细页面 url 站内各个模块都有关联 如果这个url更改了 那么代码里面 很多关于这个页面的 url 定向 都要修改 我在考虑是不是 把所有的url (包括 后台和前台) 都集中到一个表 里面 管理 然后每个url 对应有 权限 别名 rewrite 等等属性 这样 调用的时候 比如说这个 geturl("article") 根据article这个别名 来调用 url 不管url怎么改变 还是 做了 rewrite 都不用改代码了 不知道各位大神是怎么做的呢? </code>
这个可以有,最好是将mysql的url缓存到memcache或redis,不然每个请求到去查表的话,性能就不好了。
可以这样做,点评很长一段时间就是如此的。
现在因为有了SLB,软负载均衡,所以配置变的复杂了,基本都在SLB层面上做掉了。
另外这样的好处还有就是方便AB Test等同URL的应用切换。
不过有几点要注意:
1、URL匹配规则的顺序,有时会出现先前的规则覆盖后面的规则,那么URL路由就到不到后面规则的解析器。
2、URL匹配的性能,灵活利用多种匹配规则,例如starts_with, ends_with,等以及正则的写法对性能的影响。
3、楼上提到放到memcached或redis里,其实因为URL规则的访问密集性以及整体不会太大,反而是建议就放在本地内存中。
php的我不知道,不过我知道别的语言里,大多路由都需要手动注册,然后通过模版里的helper用路由名称来渲染路径,如django的urlfor

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

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.
