.htaccess根本不会改写我的网址

时间:2016-02-14 12:40:51

标签: apache .htaccess mod-rewrite

我已经在论坛上爬了大约2个小时,仍然没有找到问题的解决方案所以我转向你们寻求帮助。

我的网址如下所示 http://gymbirdz.com/article.php?url=benefits-of-fish-oil
我希望它看起来像这样 http://gymbirdz.com/article/benefits-of-fish-oil

这是我的.htaccess请求,但它不起作用,仍然没有运气修复它:/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?article/([A-Za-z0-9-]+)/?$ /article.php?url=$1 [NC,R=301,L]

非常感谢任何帮助!谢谢

更新 这就是我的.htaccess从上面看起来的方式

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^article/([A-Za-z0-9\-]+)$ article.php?url=$1 [NC,R=301,L,QSA]

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{HTTP_HOST} ^www\.gymbirdz\.com$
RewriteRule ^/?$ "http\:\/\/gymbirdz\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^192\.254\.185\.208
RewriteRule (.*) http://www.gymbirdz.com/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

2 个答案:

答案 0 :(得分:1)

尝试此规则是您的网站根目录.htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} libwww-perl [NC]
RewriteRule ^ - [F,L]

RewriteCond %{HTTP_HOST} ^www\.gymbirdz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^192\.254\.185\.208$
RewriteRule (.*) http://gymbirdz.com/$1 [R=301,NE,L]            

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{THE_REQUEST} /article\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /article/%1? [R=302,L,NE]

RewriteRule ^/?article/([\w-]+)/?$ article.php?url=$1 [NC,QSA,L]

答案 1 :(得分:-1)

也许我不明白你的问题,但这来自documentation

  

语法:RewriteRule Pattern Substitution [flags]

这是你的规则:

RewriteRule ^/?article/([A-Za-z0-9-]+)/?$ /article.php?url=$1 [NC,R=301,L]

看来你可能会颠倒这两个论点。尝试这样的事情:

RewriteRule ^article.php?url=([\w-]+) /article/$1 [NC,L,R=301,QSA]

这假定.htaccess文件与article.php位于同一目录中。