1

所以我想从 .htaccess 文件中得到通常的东西。www.example.com/article.php?title=my_title 应该替换为 www.example.com/article/my_title,但是我似乎无法让它工作。截至目前,我可以让 .php 删除,我怀疑这可能是一些问题。(我也得到http://example.comhttp://www.example.com)这是我的 .htaccess 文件

Options +FollowSymLinks -MultiViews 
rewriteengine on

## this is the piece that is not working
RewriteRule ^title/(.*) article.php?arr=title/$1

rewritecond %{HTTP_HOST} ^example.com$
rewriterule ^example\/(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301]

RewriteBase /

## Hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

## Error document (needs to have a 404 page created)
ErrorDocument 404 http://www.example.com/
4

1 回答 1

1

您需要在通常适用于 php 文件的任何规则之前添加这些特定的路由规则。所以就在你的下面rewriteengine on,添加:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/article\.php\?title=([^&\ ]+)
RewriteRule ^ /article/%1? [L,R=301]

RewriteRule ^/?article/(.*)$ /article.php?title=$1 [L]

然后是你的其余规则。

于 2012-11-01T01:50:06.520 回答