有什么不对这个的.htaccess code?有什么、htaccess、code

2023-09-02 01:15:45 作者:凉辰梦瑾°

我要在我的网站更改项目和个人资料链接到动态的。即。

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 becomes site.com/article/this_is_title_of_article for profile: site.com/ref.php?user=23 becomes site.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 将无法正常工作。

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]