【发布时间】:2013-10-01 16:37:39
【问题描述】:
我正在尝试从前两天重写。
- 强制使用 www.example.com - 完成
- 隐藏 PHP 扩展 - 已完成,但不确定这是一个好方法
- 自定义页面出现 404 错误 - 完成
现在我的主要问题是
4.在 root(/) 上托管所有页面
我有以下文件:
news.php
search.php
store.php
allstores.php
这样的客户端请求:
Type 1: http://www.example.com/news
Type 2: http://www.example.com/search?q=term
Type 3: http://www.example.com/allstores/H
Type 4: http://www.example.com/myname
我想像这样处理这些客户请求:
Type 1: http://www.example.com/news ---rewrite to (add extension)-->news.php
Type 2: http://www.example.com/search?q=term ---->No change, Let it same
Type 3: http://www.example.com/allstores/H --rewrite to --->http://www.example.com/allstores.php?ln=H
Type 4: http://www.example.com/myname ---rewrite to------> http://www.example.com/store?st=myname
我尝试了以下重写:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^(.*) store.php?st=$1 [L]
RewriteRule ^allstores/(.*)$ allstores.php?ln=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L]
ErrorDocument 404 /404.php
非常感谢您的帮助,谢谢
【问题讨论】:
-
看看我几天前的这篇帖子:stackoverflow.com/questions/33003053/…
标签: php apache .htaccess mod-rewrite url-rewriting