0

I tried following a tutorial on the internet about mod_rewrite but it wasn't really for me. I created a .htaccess file that has the following code for now:

Options +FollowSymLinks  
Options +Indexes  
RewriteEngine On  

From what I understand this is the basic setup of .htaccess to rewrite urls, followed by the instructions... what and how to change. I tried different exampled but it didn't worked for me. I have a dynamic page with the url localhost/alpha/oferta.php?id=52042156c65d4, where id="..." is the unique id of that offer. I want to change it to localhost/alpha/oferta/id=".." Can you please show me an example of how can I achieve that? Also if you know any helpful tutorials let me know. Let me know before downrating so I can edit my question. Thanks!

4

1 回答 1

1

因此,您希望将这种类型或 URL:localhost/alpha/oferta/id=123abc重定向到localhost/alpha/oferta.php?id=123abc.

Options +FollowSymLinks  
Options +Indexes  
RewriteEngine On  
RewriteBase /

RewriteRule ^alpha/oferta/id=([A-Za-z0-9]+)$ alpha/oferta.php?id=$1 [L]

记住几件事:

  • 不会神奇地将“旧”网址更改为“新”网址。您必须在任何地方使用重写(“新”)的 URL。然后,您的 htaccess 会将这个可读的 URL 更改为技术 URL,您的代码可以使用该 URL。
  • 这种重定向是透明的。如果您希望 URL 更改为浏览器栏,请使用[L,R=301]而不是[L].
  • 这将只接受字母(不区分大小写)和数字id
  • mod_rewrite 你可以在这里找到一个很好的备忘单。
于 2013-08-20T09:49:16.213 回答