Url-使用 .htaccess 重写无效

Url-rewriting using .htaccess is not working

我想要我的 url 是:http://localhost/slide-form/ad_posted.php?title=Cow%20Buffalo%20Gopal-1426356570

看起来像:http://localhost/slide-form/ad_posted/title/Cow%20Buffalo%20Gopal-1426356570/

以下是我在 htaccess 文件中添加的规则:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ad_posted/title/(.*)/ ad_posted.php?title=
RewriteRule ad_posted/title/(.*) ad_posted.php?title=                 
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.html
</IfModule>

但我的 url 没有任何变化。任何帮助深表感谢。谢谢

有两点需要注意:

  1. 确保你的apache或其他web服务器已经打开rewrite 模块。
  2. 检查您的配置设置并确保所在的目录 .htaccess 文件位于具有覆盖权限。

喜欢以下设置:

/slide-form/.htaccess中有此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /slide-form/

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

RewriteRule ^ad_posted/title/(.+)/?$ ad_posted.php?title= [L,QSA]