.htaccess文件不起作用

时间:2018-06-21 11:12:48

标签: php .htaccess

我制作了.htaccess文件,但是有些时候无法正常工作。出现一些错误,页面正在运行。我不太擅长.htaccess程序。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^index?$ index.php

RewriteRule ^page1?$ page1.php
RewriteRule ^page2?$ page2.php
RewriteRule ^page3?$ page3.php
RewriteRule ^page4?$ page4.php
RewriteRule ^page5?$ page5.php
RewriteRule ^([a-zA-Z0-9-z\-\_]+)$ profile.php?a=$1

ErrorDocument 404 "<H1>Page not found</H1>"

我有此类型的链接:

1)www.example.com?profile.php?user=userid 我需要:www.example.com/userid

2)www.example.com/about.php 我需要:www.example.com/about

3)www.example.com?list.php?list=5 我需要www.example.com/list/5

我该怎么办?

1 个答案:

答案 0 :(得分:0)

您的问题并不完全准确,但我会尝试一下:

RewriteEngine On

RewriteRule ^/?$ /index.php [L]

RewriteRule ^/?about$ /about.php [L]

RewriteRule ^/?list/(\d+)$ /list.php?list=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(\w+)$ /profile.php?user=$1 [L]

ErrorDocument 404 "<H1>Page not found</H1>"