我是第一次使用mod_rewrite。我将呈现一个场景。请告诉我是否可能。
假设我有一个数据库表,有三个属性表(id,title,parentid)。
和我的url来访问特定的内容看起来像这样:
example.com/content.php?id=some_value
现在,对于some_value id, title是some_title。有没有可能
example.com/some_title/
可以重命名为上面的url。或者
example.com/content.php?id=some_value&title=some_title
我也可以有url,如:
example.com/content.php?id=some_value&title=some_title&parenttitle=parent_title
在这种情况下,输入的url应该像这样:
example.com/parent_title/some_title/
如果我没有说清楚,请让我知道。这是我第一次尝试mod_rewrite。所以即使是很小的信息也会很有帮助。
这是你可以在。htaccess文件中添加的内容
# /id - search an ID
RewriteRule ^([0-9]+)(/?)$ /content.php?id=$1 [QSA,L]
# /title - search a title
RewriteRule ^([a-z0-9'-' ]+)$ /content.php?title=$1 [NC,QSA,L]
# /parent/child - search parent and child
RewriteRule ^([a-z'-' ]+)/([a-z0-9'-' ]+)$ /content.php?parent=$1&child=$2 [NC,QSA,L]
# /id/name - search id and title
RewriteRule ^([0-9]+)/([a-z0-9'-' ]+)$ /content.php?id=$1&child=$2 [NC,QSA,L]
# /search/some_title - search for a title
RewriteRule ^search/([a-z0-9'-' ]+)(/?)$ /search.php?q=$1 [NC,QSA,L]
等等…
不!URL重写不生成任何东西,只是改变你有别的东西!你应该把id,title或parentid放在URL中,如果你要使用它们的话!