有什么不对这个的.htaccess code? [英] What is wrong with this .htaccess code?
问题描述
我要在我的网站更改项目和个人资料链接到动态的。即。
I need to change article and profile links in my site to dynamic ones. i.e.
- 的文章:
site.com/article.php?id=12
变成site.com/article/ this_is_title_of_article
- 作为配置文件:
site.com/ref.php?user=23
变成site.com/john_doe
- for article:
site.com/article.php?id=12
becomessite.com/article/this_is_title_of_article
- for profile:
site.com/ref.php?user=23
becomessite.com/john_doe
所以我写了这的.htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]
RewriteRule ^articles/(.*)$ article.php?user=$1 [QSA,L]
所以,它的工作原理的轮廓。您可以键入 site.com/username
,和它的作品。但是,对于文章它并不─它只是不显示任何内容。
So, for the profile it works. You can type site.com/username
, and it works. But, for the articles it does not- it just does not display anything.
我不明白为什么,如果用户名是多个单词,它不会在单词之间添加下划线:即使我添加到像 site.com/john_doe $ C $网址C>将无法正常工作。
I can't understand why if username is more than one word, it does not add underscores between the words: even if I add to the URL like site.com/john_doe
it won't work.
所以,pretty的多,上面的code只为用户名,如果该用户名是只有一个字的作品。
So, pretty much, the above code works only for username AND if that username is only one word.
推荐答案
的规则从上到下进行评估,所以最有可能您的用户规则赶上一切都在你的文章规则得到一个机会。
The rules are evaluated from top to bottom, so most likely your user rule is catching everything before your articles rule gets a chance.
试试这个:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^articles/(.*)$ article.php?user=$1 [QSA,L]
RewriteRule ^(.*)$ ref.php?user=$1 [QSA,L]
这篇关于有什么不对这个的.htaccess code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!