mod_rewriter更改我的网址 [英] mod_rewriter change my url

查看:51
本文介绍了mod_rewriter更改我的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.httacess的mod_rewrited有一些问题.

I have some problems with mod_rewrited at .httacess.

我们已经创建了一个网站,该网站的链接具有此结构.

We have created a website, the website links have this sctructure.

www.myweb.com/page.php?title=this-is-the-title&filmID=454122
AND
www.myweb.com/video.php?title=this-is-the-title&filmID=2567971&player=veevr
AND
www.myweb.com/gallery/index.php?galeriID=11

可以将此结构更改为:

www.myweb.com/page/this-is-the-title/454122.html

www.myweb.com/video/this-is-the-title/454122/veevr.html

www.myweb.com/gallery/index/11.html

任何帮助都会真的很棒 感谢您阅读这篇文章! 最好的祝福 JoinOG

Any help will be really great Thank you for reading the post! Best Regards JoinOG

推荐答案

在Web根文件夹中的.htaccess文件中,输入以下代码.

In your .htaccess file in your web root folder put the following code.

RewriteEngine On

RewriteRule ^page/([^/.]+)/([0-9]+).html/?$ page.php?title=$1&filmID=$2 [L]
RewriteRule ^video/([^/.]+)/([0-9]+)/([^/.]+).html/?$ video.php?title=$1&filmID=$2&player=$3 [L]
RewriteRule ^gallery/index/([0-9]+).html/?$ gallery/index.php?galeriID=$1 [L]

这是将URL /page/something/12345.html屏蔽为page.php?title=something&filmID=12345.它会掩盖它,因此当您转到第一个URL时,它仍然看起来像地址栏中的第一个URL,但实际上位于第二个URL.有关其工作原理的简单教程位于: http://corz.org/serv/tricks/htaccess2. php

What this does is mask the url /page/something/12345.html to page.php?title=something&filmID=12345. It masks it, so when you go to the first URL it still looks like the first URL in the address bar but is really at the second URL. Simple tutorial on how this works is here: http://corz.org/serv/tricks/htaccess2.php

服务器会认为您位于文件夹/page/something/中,因此,如果您的CSS,图像和超链接是本地相对链接,则它们将无法工作,例如它会在/page/something/yourimage.png中查找链接到此<img src='yourimage.png'/>的图像.要使其按您的意愿工作,您需要在所有链接之前加一个斜杠,以使其相对于网站的根文件夹(如<img src='/yourimage.png'/>).

The server will think you are in the folder /page/something/ so if your CSS, images and hyperlinks are locally relative links they will not work, e.g. it will look in /page/something/yourimage.png for an image linked to like this <img src='yourimage.png'/>. To get it to work as you'd like it to, you'll need to put a forward slash before all your links to make it relative to your website's root folder like this <img src='/yourimage.png'/>.

这篇关于mod_rewriter更改我的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆