简体   繁体   中英

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.

For instance, my links look like users/[user_id]/ instead of 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.

Here is the code I've put in my .htaccess file:

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)/

below

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

please put this and check

and this after

RewriteEngine On

// having this rule in place we can remove the upper mentioned rule as apache will stop processing other conditions when see this rule

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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