【发布时间】:2015-02-22 18:57:22
【问题描述】:
我喜欢重写我的子域站点(通配符)以及何时将文件夹改写为 index.php 文件的参数。
所以
www.domain.com
www.domain.com/js/file.js
www.domain.com/css/file.css
www.domain.com/images/file.jpg
应该保留!
这些应该更改为 index.php 的参数
sub.domain.com/
到
www.domain.com/index.php?key1=sub
sub.domain.com/2015
到
www.domain.com/index.php?key1=sub&key2=2015
sub.domain.com/2015/12
到
www.domain.com/index.php?key1=sub&key2=2015&key3=12
这可能吗?
到目前为止我所拥有的是
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^/?(.*)$ $1?page=%1 [QSA,L,NE]
非常感谢!
所以我重写了一些@anubhava 他的 htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^/?(.*)$ $1?page=%1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^(.*)([^/][0-9]*)(/?)$ $1?page=%1&key2=$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^(.*)([^/][0-9]*)/([^/][0-9]*)(/?)$ $1?page=%1&key2=$1&key3=$2 [QSA,L]
它几乎可以工作了!
这个网址:
http://agenda.gebruikmaar.nl
变成
http://www.gebruikmaar.nl/index.php?page=agenda
但是 :-(
这个网址:
http://agenda.gebruikmaar.nl/2015
变为:
http://www.gebruikmaar.nl/index.php?page=agenda&key1=201
那么最后一个字符(5)在哪里?
【问题讨论】:
标签: .htaccess subdomain subdirectory