【问题标题】:Internal Server Error htaccess内部服务器错误 htaccess
【发布时间】:2014-10-31 15:52:36
【问题描述】:

我有如下的 htaccess 行:-

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

RewriteRule ^articles/images/(.*)$ images/$1
RewriteRule ^articles/(.*)/images/(.*)$ images/$2

RewriteRule ^articles/([a-zA-Z0-9_-]+)$ articles.php?articleType=$1
RewriteRule ^articles/([a-zA-Z0-9_-]+)/([0-9]+)$ articles.php?articleType=$1&page=$2
RewriteRule ^articles/([a-zA-Z0-9_-]+)/(.*)$ articles.php?articleType=$1&articleID=$2

问题是如果我评论RewriteRule ^(.*)$ $1.php [NC,L]http://localhost/trip/articles/Sightseeing 可以显示。但我无法显示http://localhost/trip/privacy(错误:找不到对象!)。如果我取消注释该行,我可以显示http://localhost/trip/privacy,但不能显示http://localhost/trip/articles/Sightseeing(错误:内部服务器错误)。

我已经尝试插入 <Directory /> AllowOverride All </Directory> 并得到错误:服务器错误!并插入<IfModule mod_rewrite.c>...</IfModule> 并得到错误:内部服务器错误。

有什么方法可以成功显示两个链接吗?提前致谢。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite xampp


    【解决方案1】:

    我已经解决了。对于那些和我有同样问题的人:-

    Options +FollowSymlinks
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)$ $1.php
    
    RewriteRule ^articles/images/(.*)$ images/$1
    
    RewriteRule ^articles/(.*)/images/(.*)$ images/$2
    
    RewriteRule ^articles/([a-zA-Z0-9_-]+)$ articles.php?articleType=$1 [L]
    RewriteRule ^articles/([a-zA-Z0-9_-]+)/([0-9]+)$ articles.php?articleType=$1&page=$2 
    RewriteRule ^articles/([a-zA-Z0-9_-]+)/(.*)$ articles.php?articleType=$1&articleID=$2 
    

    【讨论】:

    • 嗯,这不是一个可移植的解决方案,因为现在规则无法将 /dir/file 重写为 /dir/file.php,因为您有 ^([^/]+)$ 正则表达式模式。
    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 2016-09-22
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多