一个.htaccess的写法,麻烦,十分感谢!

WBOY
Release: 2016-06-13 10:46:40
Original
822 people have browsed it

求助一个.htaccess的写法,麻烦高手指点,十分感谢!!
原始链接格式是 xxx.com/index.php?id=xxx (ID值包含A-Z,a-z,0-9)
想要转换为 xxx.com/xxx (目录格式)
其中id=index 的时候是首页根目录

PS:我是利用Wordpress的部分函数站外调用建立的一个小站点,由于不是太懂URL重写就在WP的htaccess基础上自己摸索着添加了一部分。

出现问题:
1.不显示404页面(即使HTTP头部信息返回404并且在htaccess中设置了404页面)
2.不存在的目录(未定义目录,例如:xxx.com/test/123)HTTP头部信息返回200访问正常。
3."/"的问题,例如:xxx.com/123 不等于 xxx.com/123/

我是这样写的:

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->RewriteEngine OnRewriteBase /RewriteRule ^123/?$ index.php?id=123 [L]RewriteRule ^test/?$ index.php?id=test [L]RewriteRule ^$ index.php?id=index [L]#以上是我自己添加的规则,就用这三个变量,所以直接写的。#下面是WP的规则。RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]
Copy after login


------解决方案--------------------
那个重写就是正则写的,你对着手册就能看明白。
------解决方案--------------------
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)/?$ index.php?id=$1[L]

RewriteRule . /index.php [L]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template