.htaccess重写规则在cpanel上不工作


.htaccess rewrite rule not working on cpanel

我在我的本地主机上创建了一个网站,在htdocs中,我添加了一个文件夹'sitename',其中包含所有文件,包括。htaccess。这在我的本地工作得很好,但是当我把它上传到服务器上时,它不工作。

。htaccess代码

Options +FollowSymlinks
RewriteEngine on
RewriteBase /sitename/
# redirect to .php-less link if requested directly
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s([^.]+)'.php [NC]
#RewriteRule ^ /sitename/%1 [R,L,NC]
ErrorDocument 404 /sitename/404
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/sitename/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

在cpanel上上传时应该替换'sitename'public_html ? ?

如果您将脚本保存在子文件夹中(例如:/public_html/sitename/,那么下面的脚本应该适合您)。但是,如果您将脚本直接保存在/public_html/中(例如:/public_html/index.php),则将RewriteBase /sitename/替换为RewriteBase /

Options +FollowSymlinks
<IfModule mod_rewrite.c>
    # let the PHP knows that the mod_rewrite module is ENABLED.
    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine on
        RewriteBase /sitename/      
</IfModule>
#prevent direct access to certain file types
<FilesMatch "'.(htaccess|htpasswd|ini|log|sh|inc|bak|psd|DS_Store|project)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>
ErrorDocument 404 /sitename/404.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/sitename/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
如果您得到任何错误信息,请告诉我们-这将有所帮助。