【发布时间】:2014-11-26 17:06:21
【问题描述】:
我在使用 .htaccess 时遇到问题
这个时候我有这样的事情:
http://example.com/page-example?getVariable=1234
但我想要类似的东西:
http://example.com/page/example/1234
我尝试使用 .htacces 将连字符替换为斜线
Options +FollowSymlinks -MultiViews
RewriteRule ^([^/]+)-([^/]+).php/?$ /$1/$2 [R,L]
我得到了这样的东西
http://example.com/page/example?getVariable=1234
但是服务器找不到路径,我想是因为它承认'page'是一个文件夹。
我该怎么做,但服务器在根文件夹中搜索文件“page-example.php”而不是在“/page/”中搜索“example.php”?
PS:我已经在使用下面的代码来删除 .php 扩展名和“www”。来自网址。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
【问题讨论】:
-
你的意思是
page-example.php?吗?另外,我不经常使用rewrite,但你不是倒着做rewrite吗? -
我对重写规则也不太了解,但是你说的倒退是什么意思?
-
你的重写器是先做实际的路径而不是最后,但乔恩林给出了一个相当全面的答案。
标签: php regex apache .htaccess mod-rewrite