现有网站中的简单 mod_rewrite
我正在做一个网站(针对葡萄牙语国家),一次显示一个短语。
我希望网站有更简单的非动态地址,以便 SEO 更友好并且更容易让用户记住。所以我的问题是这样的,提前感谢所有可能的帮助:
nfrases.com/ -> completely random phrase (don't need changing this!)
nfrases.com/index.php?id_frase=2222 -> phrase with ID (wanted this to be nfrases.com/2222)
nfrases.com/tag.php?tag_nome=amor -> random phrase with tag_nome (want: nfrases.com/amor)
nfrases.com/tag.php?tag_nome=amor&id_frase=2222 -> specific phrase with tag=amor (want: nfrases.com/amor/2222)
我认为这是一个关于 mod_rewrite 的菜鸟问题,但这正是我的问题! :D 已经用我所掌握的少量知识进行了多次尝试,但要么我得到了 404 页,要么 $_GET['tag_nome'] 或 $_GET['id_frase'] 无法接收参数。
我实际拥有的 htaccess 是这样的,但它不起作用:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
RewriteRule ^([0-9]+)(.*) index.php?id_frase=$1
RewriteRule ^(.*)/([0-9]+) tag.php?tag_nome=$1&id_frase=$2 [L,QSA]
你们能帮我吗?
再次感谢一切!我很感激你的帮助。
I'm doing a website (for portuguese speaking countries) that displays phrases one at a time.
I would like to have simpler non-dynamic addresses for the site to be SEO friendlier and easier to memorize to the user. So my problem is this, and thanks in advance for all the help possible:
nfrases.com/ -> completely random phrase (don't need changing this!)
nfrases.com/index.php?id_frase=2222 -> phrase with ID (wanted this to be nfrases.com/2222)
nfrases.com/tag.php?tag_nome=amor -> random phrase with tag_nome (want: nfrases.com/amor)
nfrases.com/tag.php?tag_nome=amor&id_frase=2222 -> specific phrase with tag=amor (want: nfrases.com/amor/2222)
I think this is a noob question about mod_rewrite but that's exactly what I am! :D Already made several tries with the few knowledge I have but either i got 404 pages either the parameters wouldn't be received by the $_GET['tag_nome'] or $_GET['id_frase'].
The actual htaccess I have is this but it isn't working:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
RewriteRule ^([0-9]+)(.*) index.php?id_frase=$1
RewriteRule ^(.*)/([0-9]+) tag.php?tag_nome=$1&id_frase=$2 [L,QSA]
Can you guys help me?
Thanks again for everything! I appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下重写规则适用于我的 RewriteRule 测试器:
The following rewrite rules work for me on a RewriteRule tester:
您可能想要这样的内容:
在这种情况下,nfrases.com/2222 将重写为index.php/2222。这可以轻松地在您的index.php 文件中允许基本路由。对于更高级的路由,使用一个好的框架可能会更快更容易。查看 FuelPHP (http://www.fuelphp.com) 或 CodeIgniter (http://www.codeigniter.com)。
You may want something like this:
In this case, nfrases.com/2222 will rewrited as index.php/2222. This easily allows base routing in your index.php file. For more advanced routing, it may be faster and easier to use a good framework. Take a look at FuelPHP (http:www.fuelphp.com) or CodeIgniter (http://www.codeigniter.com).