简体   繁体   English

.htaccess新手问题,使用mod_rewrite

[英].htaccess newbie issue using mod_rewrite

I need to create SEO-friendly urls for my site. 我需要为我的网站创建SEO友好的URL。 I found out I can use .htaccess to rewrite them. 我发现我可以使用.htaccess重写它们。 So I tried this: 所以我尝试了这个:

> http://www.domain.com/page/1/mypage
> http://www.domain.com/user/2/myuser
> http://www.domain.com/help/3/myhelp

Now I am stuck with a common rule and I don't understand Ant to redirect traffic based on the name of the page: 现在,我坚持了一条通用规则,而且我不了解Ant根据页面名称重定向流量:

I use: 我用:

RewriteEngine ON
RewriteRule ^(.*)$ page.php?page=$1

Then in my PHP I don't get the page correctly, I get the file which is wrong. 然后在我的PHP中,我无法正确获取页面,我得到了错误的文件。

How can I fix this? 我怎样才能解决这个问题?

Here's what you need to do: 这是您需要做的:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z_\-]+)/([0-9]+)/([a-z_\-]+)/?$ page.php?page=$1&id=$2&name=$3 [NC,L]

NC (or nocase) Makes the test case-insensitive, A = a; NC (或nocase)使测试不区分大小写,A = a;

L (or last) Last rule. L (或最后一条)最后一条规则。 Stop the rewriting process here and don't apply any more rewrite rules; 在此处停止重写过程,不要再应用任何重写规则;

You can get more info at http://httpd.apache.org/docs/current/mod/mod_rewrite.html 您可以在http://httpd.apache.org/docs/current/mod/mod_rewrite.html上获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM