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

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

问题描述

我使用htaccess的首次做出pretty的网址为我的网站的HTML文件和1 PHP文件。我只是想知道如果我能得到我的htaccess文件中的一些建议设置,如果我是如何将它设置了一个好办法?我讨厌我的网址无法在某些情况下,因为我自己编写工作。 :(

例如HTML文件:

 前:http://www.domain.com/subdomain/htmlpage.html
后:http://www.domain.com/subdomain/htmlpage/
 

一个PHP文件:

 前:http://www.domain.com/subdomain/phppage.php?p=1
后:http://www.domain.com/subdomain/phppage/1/
 

我在规则中增加了重定向的index.html的index.php。我也有加入'基地的HREF'中的每个文件的头,因为我已经使用相对链接。

htaccess的文件:

 选项+了FollowSymLinks
RewriteEngine叙述上
重写规则^指数\ html的?$ / [NC,R,L]
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则。* [^ /] $%{REQUEST_URI} / [L,R = 301]
的RewriteCond%{} REQUEST_FILENAME html的-f
重写规则^(+)/ $ $ 1.HTML [L]
重写规则^(+)/([0-9] +)/ $ phppage.php?P = $ 1 [L]
 

解决方案

这行

 重写规则^(+)/([0-9] +)/ $ phppage.php?P = $ 1 [L]
 

是要送一些页面phppage.php即使他们不喜欢看

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

因为在第一个参数重写规则没有提及phppage的。

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. :(

Example html file:

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

Single php file:

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

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.

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]

解决方案

This line

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

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

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

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

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

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