Php 为日历站点重写URL

Php 为日历站点重写URL,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我正在尝试使用.htaccess使我的日历站点的URL看起来更好,但我无法使它工作 我已经有了一个删除.php扩展名的规则,而且它工作得非常完美。看起来是这样的: RewriteEngine On # turn on the mod_rewrite engine RewriteCond %{REQUEST_FILENAME}.php -f # IF the request filename with .php extension is a file which exists RewriteC

我正在尝试使用.htaccess使我的日历站点的URL看起来更好,但我无法使它工作


我已经有了一个删除.php扩展名的规则,而且它工作得非常完美。看起来是这样的:

RewriteEngine On
# turn on the mod_rewrite engine

RewriteCond %{REQUEST_FILENAME}.php -f
# IF the request filename with .php extension is a file which exists
RewriteCond %{REQUEST_URI} !/$
# AND the request is not for a directory
RewriteRule (.*) $1\.php [L]
# redirect to the php script with the requested filename
我当前的URL如下所示:

。。。我想让它看起来像这样:

该网站在没有重写的情况下工作得非常完美,我使用$_GET[]在URL中获取年和月的值,但如果启用重写,它无法从URL中获取值


我已经试过这些(当然不是同时两种):

第一个创建一个404页面,第二个无法从url获取值,这会弄乱样式表


希望你们能帮我:D


谢谢-Jesper

你很接近,但在你的第一次尝试中,你只包括一个匹配组,而不是一个匹配组。包含字符类两次,以匹配捕获到的年份
$1
,再次包含捕获到的月份
$2
。使用
RewriteBase
设置重定向的根目录。请注意,“月”值与URL中的情况相同

RewriteEngine on
RewriteBase /
RewriteRule ^calendar/([^/]*)/([^/]*)$ /calendar/calendar-site.php?year=$1&month=$2 [L]
测试使用


忘了说,.htaccess文件位于“日历”文件夹中,而不是我网站的根目录中。谢谢,伙计:)重写库解决了我的问题。这是我的代码:RewriteBase/kalender/RewriteRule^([^/]*)/([^/]*)$/kalender/calendar test?year=$1&month=$2[L],但未加载css文件。似乎网站认为它所处的位置不对。你知道怎么解决吗DIt似乎不知道css是一个实际的文件
RewriteEngine on
RewriteBase /
RewriteRule ^calendar/([^/]*)/([^/]*)$ /calendar/calendar-site.php?year=$1&month=$2 [L]
input url
http://mydomain.com/calendar/2013/november

output url
http://mydomain.com/calendar/calendar-site.php

debugging info
1 RewriteBase /
2 RewriteRule ^calendar/([^/]*)/([^/]*)$ /calendar/calendar-site.php?year=$1&month=$2 [L]
  This rule was met, the new url is http://mydomain.com/calendar/calendar-site.php
  The tests are stopped because the L in your RewriteRule options