2017-04-21 94 views
0

大家好我已经使用PHP将这个应用程序与不同的页面链接在一起。该应用程序工作正常,但生成的URL非常混乱和复杂。我在我的应用程序即在PHP中的URL重写

1.index.php (the default file) 
2.video.php (the category page) 
3.video-detail.php(the page for playing the video) 

三页和根文件夹的名称是april

现在,它们是为应用程序生成的链接。

http://localhost/april/video?cat_id=2&category=Programming-Language 

考虑到我在第二页浏览某个类别后,在第一页的用户输入了一些内容。现在我正在尝试让URL比这更干净。例如:URL应该采用这种格式。

http://localhost/april/Programming-Language. 

我知道这个任务是使用.htacess实现的,但我无法真正理解它的方法。所以有关这个话题的任何帮助,我都非常感谢

+0

你正在使用哪个框架? – lalithkumar

+0

只是基本的PHP。以及Apache服务器。 –

+0

你必须在.htaccess – lalithkumar

回答

0

http://localhost/april/video?category=Programming-Language&cat_id=2

这可以转化为: http://localhost/Programming-Language/2

(通知我转移cat_id到最后,因为我怀疑它是一个页号)

这是通过将以下内容放入您的.htaccess

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)$ /april/video?category=$1&cat_id=$2 [L] 

很明显,你可以然后通过$_GET请求($_GET['category']

+0

上尝试使用这种方法来使RewriteEngine开启。没有解决..这是我的htaccess文件。 –

+0

@HarjeevSingh对于初学者,请在没有其他东西的情况下尝试一下,另外,请确保正确使用它。 –

+0

所以我碰到这个代码'RewriteRule^products /([0-9] +)/?$ show_a_product.php?product_id = $ 1',但我似乎无法确定什么是转换什么。我的意思是教程说它会在URL中查找特定模式,然后将其转换为完整的混乱链接。但是这个过程不应该是相反的。 –