简体   繁体   English

使用htaccess和PHP重写URL

[英]URL rewriting using htaccess and PHP

I'm a beginner to htaccess. 我是htaccess的初学者。 I have a url 我有一个网址

www.example.com/article/details?id=2&category=sports&subcategory=cricket&url=ricky-ponting

I'm trying to rewrite this URL in htaccess. 我正在尝试在htaccess中重写此URL。 I want the above url should be formatted as: 我希望以上网址的格式应为:

www.example.com/sports/cricket/ricky-ponting

I want to hide article, details and id from the URL 我想从URL隐藏文章,详细信息和ID

I don't know how to create this URL. 我不知道如何创建此URL。 Is it possible to handle the hidden ID parameter in URL in backend using PHP? 是否可以使用PHP处理后端URL中的隐藏ID参数?

Thanks in advance. 提前致谢。 Any help will be appreciated. 任何帮助将不胜感激。

Put a htaccess file in project root by following code. 通过以下代码将htaccess文件放在项目根目录中。

DirectoryIndex index.php
RewriteEngine on                       
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 

now you can customize your url. 现在您可以自定义您的网址了。 User your get parameter after controller and method. 在控制器和方法之后使用您的get参数。 like: www.example.com/article/details/sports/cricket/ricky-ponting 像:www.example.com/article/details/sports/cricket/ricky-ponting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM