Reputation: 2424
im having some difficulty with Rewrite Rules. My .htaccess
looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule admin/add-category$ adm_add_category.php [NC]
RewriteRule admin/categories-management$ adm_categories_management.php [NC]
RewriteRule admin/user-settings/(.*)$ adm_user_settings.php?update=$1 [NC]
RewriteRule admin/website-settings/(.*)$ adm_website_settings.php?update=$1 [NC]
RewriteRule admin/users-management$ adm_users_management.php [NC]
RewriteRule admin/websites-management$ adm_websites_management.php [NC]
RewriteRule settings/profile$ changesettings.php [NC]
RewriteRule settings/websites$ my_websites.php [NC]
RewriteRule settings/password$ changepassword.php [NC]
RewriteRule settings/logout$ logout.php [NC]
RewriteRule pages/index$ index.php [NC]
RewriteRule pages/access$ access.php [NC]
RewriteRule pages/submit-url$ submit_url.php [NC]
RewriteRule pages/online-users$ online_users.php [NC]
RewriteRule pages/register$ register.php [NC]
RewriteRule pages/websites$ websites_list.php [NC]
RewriteRule pages/websites/(.*)$ websites_list.php?page=$1 [NC]
RewriteRule pages/contact$ contact.php [NC]
RewriteRule search/(.*)$ search.php?term=$1 [NC]
RewriteRule category/(.*)$ category.php?name=$1 [NC]
RewriteRule profile/(.*)$ profile.php?username=$1 [NC]
RewriteRule website/(.*)$ website.php?name=$1 [NC]
All of the rewrites except for the following are working:
RewriteRule search/(.*)$ search.php?term=$1 [NC]
RewriteRule category/(.*)$ category.php?name=$1 [NC]
RewriteRule profile/(.*)$ profile.php?username=$1 [NC]
RewriteRule website/(.*)$ website.php?name=$1 [NC]
When trying to load a specific profile, such as /profile/exampleguy, a 404 error is shown. Does anyone know what would cause this?
The 404 looks like:
The requested URL /profile/exampleguy was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Let me know if you need more information, i really appreciate the help!
Upvotes: 2
Views: 2244
Reputation: 785246
Add L
flag in each rule to make it [NC,L]
and then add:
Options +FollowSymLinks -MultiViews
at top of .htaccess
Upvotes: 5
Reputation: 4913
Have you tried working in some rewrite conditions to redirect to a default page?
RewriteCond %{REQUEST_FILENAME} !-d //Rewrites if the directory doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f //Rewrites if the file doesn't exist
RewriteRule ^(.*)$ index.php?$1 [L,QSA] // Change this to suit your needs
Also, I would surmise you are getting the 404 because directories like /profile/ actually exists, but not an "exampleguy" and if there isn't another .htaccess in those directories to catch the issue then the server will try to find the page (and fail....)
Upvotes: 1