我工作在本地服务器上上html/php
应用程序,我想使用Apache URL重写模块没有成功的.htaccess URL重写工作,但不是重定向
应用程序存储在./Compta/index.php
。我有一个.htaccess
文件./Compta/.htaccess
我想只使用一个重写URL,如:http://localhost/Compta/Test/
代替:http://localhost/Compta/index.php?page=test
和重定向用户,如果他们试图去旧的URL
.htaccess文件包含:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([[:alnum:]]*)/$ /Compta/index.php?page=$1 [L]
RewriteRule ^([[:alnum:]]*)$ /Compta/index.php?page=$1 [L]
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^page=([[:alnum:]]*)$
RewriteRule ^(.*)$ http://localhost/Compta/%1/ [L,R=301]
当我去Ť Øhttp://localhost/Compta/Test/
下面一行是工作,我的代码在一个div包括test.php
内容:
RewriteRule ^([[:alnum:]]*)/$ /Compta/index.php?page=$1 [L]
当我去http://localhost/Compta/Test
以下行工作,但在Firefox的URL改写为http://localhost/Compta/index.php?page=Test
,这是不会发生与http://localhost/Compta/Test2
;网址不会被重写。
RewriteRule ^([[:alnum:]]*)$ /Compta/index.php?page=$1 [L]
要解决这个问题,并重定向旧的URL我添加这些行:
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^page=([[:alnum:]]*)$
RewriteRule ^(.*)$ http://localhost/Compta/%1/ [L,R=301]
但这不工作,当我去http://localhost/Compta/index.php?page=Test
的网址不被改写,以http://localhost/Compta/Test/
预先感谢您