Expanding friendly url, mod rewrite

拟墨画扇 提交于 2020-01-17 02:37:35

问题


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]

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

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.


回答1:


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 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 :)



来源:https://stackoverflow.com/questions/8429034/expanding-friendly-url-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!