简体   繁体   English

.htaccess中的mod_rewrite导致目录导致错误500

[英]mod_rewrite in .htaccess causing directories to lead to error 500

I've been modifying my website URLs in order to beautify them a bit, but I'm currently having an issue regarding to the site directories. 我一直在修改我的网站URL,以美化它们,但是我目前在网站目录方面遇到问题。

For instance, my links look like users/[user_id]/ instead of users.php?p=[user_id] . 例如,我的链接看起来像users/[user_id]/而不是users.php?p=[user_id] Everything is working well apart of the directories, as said above. 如上所述,除目录外,其他所有程序都运行良好。

When I try to access, for instance, to www.mywebsite.com/js/ , I'm facing an error 500 from the server, which, hypothetically, means that there is no file/directory with this name, because of the RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d line. 例如,当我尝试访问www.mywebsite.com/js/ ,服务器面临错误500,假设由于RewriteCond %{REQUEST_FILENAME} !-f ,这意味着不存在具有该名称的文件/目录。 RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d行。

Here is the code I've put in my .htaccess file: 这是我放入.htaccess文件中的代码:

RewriteEngine On
RewriteRule ^users/([0-9]+)/?$ /user.php?p=$1
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/?$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1.php
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

# Error Documents Redirect
ErrorDocument 404 http://www.mywebsite.com/notFound/
ErrorDocument 403 http://www.mywebsite.com/forbidden/
ErrorDocument 401 http://www.mywebsite.com/unauthorized/

# Options
Options All -Indexes
Options All +FollowSymLinks

I don't really understand, as I just started working on this for the first time like a few hours ago, and I just start to understand the regex, and path formatting. 我不太了解,因为就像几个小时前我才刚开始做这个一样,我只是开始了解正则表达式和路径格式。

I hope you'll be able to help me, and through this, help people facing this issue too. 希望您能够对我有所帮助,并通过此方式也帮助面临此问题的人们。

Regards 问候

add this 加上这个

RewriteCond %{REQUEST_URI} !^/(css|js)/ RewriteCond%{REQUEST_URI}!^ /(css | js)/

below 下面

RewriteRule ^(.*)$ http://www.mywebsite.com/ ?$1 [L,R=301,NC] RewriteRule ^(。*)$ http://www.mywebsite.com/?$ 1 [L,R = 301,NC]

please put this and check 请把这个检查

and this after 然后这个

RewriteEngine On RewriteEngine开

// having this rule in place we can remove the upper mentioned rule as apache will stop processing other conditions when see this rule //有了此规则,我们可以删除上面提到的规则,因为当看到此规则时,apache将停止处理其他条件

RewriteRule ^(css|jss)($|/) - [L] RewriteRule ^(css | jss)($ | /)-[L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM