带有多个参数的友好URL
I've been trying many different examples I browsed on this forum and other websites to create the urls more user friendly with no success. I'll try my luck with all of you experts here.
I've got a structure of my url that looks like this:
index.php?mod=post&id=10
The mod parameter can contain an array of different keys, each one will include a defined module to the template.
I was hoping to achieve something similar to:
my-url.com/post/10
At the moment I am only interessted to change the url when the value of mod
equals to post
.
Any ideas and suggestions are welcome.
我一直在尝试我在这个论坛和其他网站上浏览的许多不同的例子来创建更加用户友好的网址 没有成功。 我会和你们所有的专家一起试试我的运气。 p>
我的网址结构如下: p>
\ nindex.php?mod = post& id = 10 p> blockquote>
mod参数可以包含不同键的数组,每个键都包含一个已定义的模块 模板。 p>
我希望能达到类似的目的: p>
my-url.com/post/10 blockquote>
目前我只是在
mod code>的值等于
post code>时更改url。 p>
欢迎任何想法和建议。 p> div>
Try this in your public_html/.htaccess :
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?mod=([^&]+)&id=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?mod=$1&id=$2 [QSA,L,NC]