2012-01-07 77 views
1

存在URL重写正在运行但服务器不显示内容的问题。我的.htaccess文件是htaccess URL重写 - 在服务器上找不到请求的URL

RewriteEngine On 
    RewriteBase/
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /project\.php [NC] 
    RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] 
    RewriteRule . project-%1.html? [R=301] 

感谢您的帮助!

编辑:对不起,这里有一些更多的信息!

我想重写

www.siteurl.co.uk/project.php?id=82 

www.siteurl.co.uk/project-82.html 

在.htaccess的代码重写URL完美,但该页面不显示。我得到一个

404 The requested URL /project-82.html was not found on this server. 

我希望有帮助!

+2

你忘了描述您的问题,反问 – zerkms 2012-01-07 00:30:01

+0

不知道要配什么发送简洁的URL与应用程序进行处理?几乎不可能知道从哪里开始 – 2012-01-07 00:31:10

+0

对不起,这是从另一个问题继续,我忘了添加所有的信息!我现在编辑它! – 5ummer5 2012-01-07 00:44:28

回答

1

您只有一半的解决方案,创建漂亮的网址。现在缺少的是另一半,如下

RewriteEngine On 
RewriteBase/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /project\.php [NC] 
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] 
RewriteRule . project-%1.html? [R=301] 

#you need this rule to process your www.siteurl.co.uk/project-82.html request 
RewriteRule ^project-([0-9]+)\.html$ project.php?id=$1 [L,NC,QSA] 
+0

这已经完成了!非常感谢你! – 5ummer5 2012-01-07 02:57:46

0

尝试把RewriteRule ^project-%1.html? [R=301]代替.

+0

这就是答复。我刚刚尝试过,它根本没有重写URL。 – 5ummer5 2012-01-07 00:57:58

0

不知道是什么的 “[A-Z] {3-9} \” 是?也许我错过了什么?

但也许这样的事情,而不是:

RewriteCond %{THE_REQUEST} ^project\.php [NC] 
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] 
RewriteRule . project-%1.html? [R=301] 

RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] 
RewriteRule ^/project\.php project-%1.html? [R=301] 

请注意,这只是从我的头顶,我没有测试它。

编辑:只是调整,其中有在它的一个额外的斜杠,并测试了它在我的网络服务器的第二个例子(注意,我使用的是IIS/URLRewrite,而应该是相同的):

RewriteBase/
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] 
RewriteRule ^project\.php project-%1.html? [R=301] 

我进入HTTP://localhost/project.php ID = 123它去HTTP://localhost/project-123.html

但我想我错过了一些东西...你说网址重写正在工作,并且网址正在改变,但你是获得404?在那种情况下,你的重写听起来不错 - 而其他的东西不允许访问你的html文件(或者它们不存在)?

+0

感谢您的回复!我担心这些工作并没有保持相同的URL。我不知道什么是“[A-Z] {3-9}”,但它适用于它。除了加载页面! – 5ummer5 2012-01-07 00:55:50

+0

编辑完成了这个技巧,并重写了URL。你说的是project-82.html文件不存在是正确的。我只想让网址阅读www.siteurl.co.uk/project-82.html而不是www.siteurl.co.uk/project.php?id=82。 – 5ummer5 2012-01-07 01:48:10

相关问题