Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 谁能帮我修改一下网址吗?_.htaccess - Fatal编程技术网

.htaccess 谁能帮我修改一下网址吗?

.htaccess 谁能帮我修改一下网址吗?,.htaccess,.htaccess,我正在开发一个文件共享网站,现在我想创建seo友好的URL。我尝试了不同的.htaccess代码来实现,任何人请帮助我实现 我有一个页面www.mydomain.com/gallery.php?id=2&title=newimage 我希望通过www.mydomain.com/newimage/1.html 请给我.htaccess代码来重写www.mydomain.com/gallery.php?id=2&title=newimage到www.mydomain.com/newimage/1.h

我正在开发一个文件共享网站,现在我想创建seo友好的URL。我尝试了不同的.htaccess代码来实现,任何人请帮助我实现

我有一个页面
www.mydomain.com/gallery.php?id=2&title=newimage

我希望通过
www.mydomain.com/newimage/1.html


请给我.htaccess代码来重写
www.mydomain.com/gallery.php?id=2&title=newimage
www.mydomain.com/newimage/1.html

假设12确实是相同的id,您可以在文档根目录中将这些规则添加到htaccess文件中:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ReewriteRule ^/?([^/]+)/([^/.]+)\.html$ /gallery.php?id=$2&title=$1 [L]
当有人进入
http://mydomain.com/foo/bar.html
,他们可以在
/gallery.php?id=bar&title=foo
获得内容

为了纠正所有超出您控制范围的外部链接,以开始使用新的外观更好的URL,您也可以添加以下内容:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /gallery\.php\?id=([^&]+)&title=([^\ ]+)
RewriteRule ^ /%2/%1.html? [L,R=301]

当有人把
http://mydomain.com/gallery.php?id=123456&title=blah
,浏览器被重定向到
http://mydomain.com/blah/123456.html
,从而将浏览器地址栏中的地址更改为外观更好的URL。

因此示例中的
gallery.php
id为2,但是在友好的URL中,您有
1.html
。那么1和2之间没有任何关系?你是不是特别向对方重写了这个请求?