3

I'm having a problem with my mod rewrite rule that I wrote for my website, nothing seems to change as my pages URL are loading the same as before, if anyone could have a look at it and let me know if there is any problems it would be very much appreciated, thanks!

REWRITE RULE

RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?art_id=$1 [L]

URL

http://www.test.com/index.php?art_slug=test

DESIRED RESULT

http://www.test.com/test
4

3 回答 3

2

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# to externally redirect from /index.php?art_slug=test to /art_slug/test
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+/(?:index\.php|)\?([^=]+)=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

# to internally forward from /art_slug/test to /index.php?art_slug=test
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/(.+)$ /index.php?$1=$2 [L,QSA]

确认它工作正常后,替换R=302R=301. R=301在测试你的 mod_rewrite 规则时避免使用(永久重定向)。

于 2013-05-22T03:16:00.977 回答
0
RewriteEngine On 
RewriteBase / 
RewriteRule ^(.*)$ index.php?art_id=$1 [L]

应该管用。:)

于 2013-05-22T02:49:54.220 回答
0
RewriteEngine On
RewriteRule (.*)/$ search.php?keyword=$1

应该管用。:)

于 2016-04-01T12:42:36.140 回答