doubi4435 2016-09-06 07:13
浏览 45

.htaccess重写规则不适用于cpanel

I have created a website on my localhost, Inside htdocs I have added a folder 'sitename' this contains all files including .htaccess. This is working fine on my local, but when I am uploading it on server the its not working.

.htaccess code

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]

What should be the replacement for 'sitename' while uploading on cpanel public_html??

  • 写回答

1条回答 默认 最新

  • dongxia2068 2016-09-06 07:25
    关注

    If you keep your scripts in a sub-folder (example: /public_html/sitename/ than below should work for you). However, if you keep your scripts directly in /public_html/ (example: /public_html/index.php) than replace RewriteBase /sitename/ with 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]
    

    Let us know if you get any error message - it would help.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口