htaccess 漂亮的网址设置 [英] htaccess pretty urls setup

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

问题描述

我第一次使用 htaccess 为我的网站 html 文件和 1 个 php 文件制作漂亮的 url.我只是想知道我是否能够得到一些关于我的 htaccess 文件设置的建议,以及我如何设置它是否是一个好方法?由于我所写的内容,我讨厌我的网址在某些情况下不起作用.:(

I'm using htaccess for the first time to make pretty urls for my website html files and 1 php file. I was just wondering if I would be able to get some advice on my htaccess file set up and if how I have it set up is a good way? I'd hate for my urls to not work in some situation because of what I have written. :(

示例 html 文件:

Example html file:

before:  http://www.domain.com/subdomain/htmlpage.html
after:   http://www.domain.com/subdomain/htmlpage/

单个php文件:

before:  http://www.domain.com/subdomain/phppage.php?p=1
after:   http://www.domain.com/subdomain/phppage/1/

我添加了将 index.html 重定向到 index.php 的规则.我还不得不在每个文件的头部添加base href",因为我使用了相对链接.

I have added in a rule to redirect index.html to index.php. I've also had to add 'base href' in the head of each file because I've used relative links.

htaccess 文件:

the htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index.html?$ / [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]
RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L]

推荐答案

此行

RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L]

将把一些页面发送到 phppage.php 即使它们看起来不像

is going to send some pages to phppage.php even though they don't look like

http://www.domain.com/subdomain/phppage/1/

因为在 RewriteRule 的第一个参数中没有提到 phppage.

because there is no mention of phppage in the first argument to RewriteRule.

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

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