使用PHP或Apache重定向清理URL

时间:2012-07-14 03:52:39

标签: php

  

可能重复:
  Redirect *.php to clean URL

我确信之前已经问过这个问题,但出于某些原因,无论我尝试什么似乎都不起作用。

我拥有的是: http://example.com/share/edit.php?id=59

我想要的是: http://example.com/share/59

我的.htaccess是:

RewriteEngine on
RewriteRule ^share/([0-9]+)$ share/edit.php?id=$1

我做错了吗? .htaccess文件位于example.com/share目录中。

4 个答案:

答案 0 :(得分:0)

尝试将.htaccess放到example.com目录。

答案 1 :(得分:0)

尝试这样做:

RewriteEngine On
RewriteRule ^share/([^/]*)$ /share/edit.php?id=$1 [L]

您的.htaccess文件应位于根目录,即example.com的目录中。那里有share文件夹。

答案 2 :(得分:0)

如果.htaccess位于共享目录中,则无需指定URL路径。尝试这样的事情:

RewriteEngine On
RewriteRule ^(.*)$ edit.php?id=$1 [QSA,L]

不言而喻,如果您使用apache,则需要启用mod_rewrite。

答案 3 :(得分:-1)

  

'.htaccess'文件位于'example.com/share'目录中。

将其移至上一级目录(public_html或www)。