我用这两行重写任何URL,如www.example.com/spyke(其中spyke是用户名,可以是任何用户名)。。
RewriteCond %{REQUEST_URI} ^/([^/]+)? [NC]
RewriteRule ^/([^/]+)? http://www.example.com/index.php?id=82&user=$1 [L,R=301]
此ALMOST有效,但系统当前重定向到的URL为:
www.example.com/index.php?id=82&user=index.php
而不是
www.mydomain.com/index.php?id=82&user=spyke
1) 因此,我想将www.mydomain.com/spyke重写为www.example.com/index.php?id=82&user=spyke
。。有人知道如何做到这一点吗?
2) 此外,我希望用户在地址栏中看到www.example.com/spyke
,而不是www.example.com/index.php?id=82&user=spyke
——这也可能吗?
谢谢!!!!!
Roel
这是我的(更新的)htaccess文件btw:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/typo3$ - [L]
RewriteRule ^/typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php
RewriteRule ^/([a-zA-Z0-9_-]+)? http://www.example.com/index.php?id=82&user=$1 [L,R=301]
</IfModule>
但这只会导致这个链接:http://www.example.com/index.php?id=82&user=索引
使用此htaccess:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=82&user=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=82&user=$1 [L]
当请求"www.example.com/spyke"时
这个htaccess加载"index.php?id=82&user=spyke"而不是那个
如果存在,这几行加载一个文件!
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
如果请求的URL不是文件,则加载"index.php?id=82&user=[string]"
试试这个:
RewriteRule ^author/(.+)$ index.php?pagename=books&author=$1
我在这里找到了:重定向5号
在您的情况下,您应该使用:
RewriteRule ^(.+)$ index.php?id=82&user=$1