我喜欢重写我的子域网站(通配符),以及当index.php文件存在params时的文件夹。
所以
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)在哪里?
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^/?$ index.php?key1=%1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^([^/]+)/?$ index.php?key1=%1&key2=$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?key1=%1&key2=$1&key3=$2 [QSA,L]