扩大友好的URL,mod-rewrite友好、URL、rewrite、mod

2023-09-02 10:10:29 作者:是我闯入你的生活

我使用镆铘,这是一个CMS系统。它有一个友好的URL选项,使用这样的htaccess的。

I am using modx, which is a cms system. It has a friendly url-option and uses a .htaccess like this.

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

如果让URL看起来像:mysite.com/about和mysite.com/about/contact

If makes the url look like: mysite.com/about and mysite.com/about/contact

我想扩大这个htaccess的,这样我就可以写myste.com/about/2没有第2页实际存在的。我想有访问此在GET变量的能力。可以这样做?我在这方面没有任何知识。

I'd like to expand this .htaccess, so I can write myste.com/about/2 without the page 2 actually existing. I'd like to have the ability to access this in a get-variable. Can this be done? I have no knowledge at this area whatsoever.

推荐答案

您的可以的做到这一点在你的.htaccess,但更好的方法可能是创建一个插件,在OnPageNotFound事件触发。

You could do this in your .htaccess, but a better way might be to create a plugin that fires on the OnPageNotFound event.

myste.com/about/2不存在,那么就会引发你的插件,它会发送到用户的404页面之前运行。在这种情况下,您可以从URL的末尾拆分/ 2,并用它来拉你的数据或发送的要404用户到不同的页面,而不是。

myste.com/about/2 does not exist so it will trigger your plugin which will run before sending the user to the 404 page. In this case, you can can split the /2 from the end of the url and use it to pull in your data or send the user to a different page instead of going to 404.

这是否有意义吗?这是一个有点困难不知道到底要做些什么贡献更多:)

Does that make sense? It's a bit difficult to contribute more without knowing exactly what you want to do :)