根和子文件夹htaccess的重写的index.php [英] htaccess rewrite index.php on root and subfolders
问题描述
我想重定向所有请求./index.php?site=$1,而我只是想用最后的斜线后面的部分。
所以,我想 www.mydomain.com/firstpage
成为 www.mydomain.com/index.php?site=firstpage
和www.mydomain.com/subfolder/anotherpage成为 www.mydomain.com/subfolder/index.php?site=anotherpage
但现在 www.mydomain.com/subfolder/anotherpage
变
www.mydomain.com/index.php?site=subfolder/anotherpage
这是我有:
RewriteEngine叙述上
选项+ SymlinksIfOwnerMatch
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ mydomain.com $ [NC]
重写规则^(。*)$ http://www.mydomain.com/$1 [R = 301,L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php?site=$1 [L]
我能做的重定向只有最后一个斜杠后面的部分?
太谢谢你了!
解决方法:
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则(。* /)?([^ /] +)$ $ 1index.php?网站= $ 2 [L]
发现这个其他的,在我看来,更好的解决方案。由此,子文件夹的数量是不相关的。
解决方法:
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则(。* /)?([^ /] +)$ $ 1index.php?网站= $ 2 [L]
I'm trying to redirect all requests to ./index.php?site=$1 while I only want to use the part behind the last slash.
So I want www.mydomain.com/firstpage
to become www.mydomain.com/index.php?site=firstpage
and www.mydomain.com/subfolder/anotherpage to become www.mydomain.com/subfolder/index.php?site=anotherpage
But right now www.mydomain.com/subfolder/anotherpage
becomes
www.mydomain.com/index.php?site=subfolder/anotherpage
This is what I've got:
RewriteEngine on
Options +SymlinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?site=$1 [L]
What could I do to redirect only the part after the last slash?
Thank you so much!
SOLUTION:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*/)?([^/]+)$ $1index.php?site=$2 [L]
Found this other, on my opinion more elegant solution. By this, the number of subfolders is irrelevant.
SOLUTION:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*/)?([^/]+)$ $1index.php?site=$2 [L]
这篇关于根和子文件夹htaccess的重写的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!