为日历创建漂亮的URL

时间:2013-11-11 13:29:15

标签: regex apache .htaccess url mod-rewrite

我正在尝试为我的日历网站创建一个漂亮的网址。 但我无法让它正常工作。

这是我的网址:

  

http://mydomain.com/admin/calendar?year=2013&month=november

......我希望它看起来像这样:

  

http://mydomain.com/admin/calendar/2013/november

“日历”文件夹是一个真正的文件夹,.htaccess文件位于admin文件夹中,而不是位于我网站的根目录中。< / p>

我目前正在使用此代码:

RewriteEngine On

# Make sure not to rewrite real files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# Removes PHP extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

# Make new URL
RewriteBase /admin/
RewriteRule ^([^/]*)/([^/]*)$ /admin/calendar/calendar?year=$1&month=$2 [L]

知道为什么这不起作用,以及如何让它工作? :d

谢谢:) TheYaXxE

2 个答案:

答案 0 :(得分:1)

admin/.htaccess文件中试用此代码:

RewriteEngine On
RewriteBase /admin/

# Make sure not to rewrite real files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Make new URL
RewriteRule ^calendar/([^/]+)/([^/]*)/?$ calendar.php?year=$1&month=$2 [NC,L,QSA]

# Removes PHP extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+?)/?$ $1.php [L]

答案 1 :(得分:0)

试试这个:

RewriteRule ^([^/]+)/([^/]+)/$ /admin/calendar/calendar?year=$1&month=$2