【发布时间】:2017-05-08 13:48:43
【问题描述】:
我正在使用 html/php 应用程序上的本地服务器,我正在尝试使用 Apache url 重写模块但没有成功
应用程序存储在./Compta/index.php。我必须在./Compta/.htaccess 中创建一个.htaccess 文件
我只想使用重写后的网址,例如:http://localhost/Compta/Test/
而不是:http://localhost/Compta/index.php?page=test
如果用户尝试转到旧网址,则重定向用户
.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 不会发生这种情况; url 没有被重写。
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/index.php?page=Test 时,网址不会重写为 http://localhost/Compta/Test/
提前谢谢你
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite mod-alias