1

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!

Prix
  • 18,774
  • 14
  • 65
  • 127
ThatGuy343
  • 2,194
  • 2
  • 23
  • 49

2 Answers2

4

Add L flag in each rule to make it [NC,L] and then add:

Options +FollowSymLinks -MultiViews

at top of .htaccess

anubhava
  • 664,788
  • 59
  • 469
  • 547
  • This fixed it. Thanks! – ThatGuy343 Sep 25 '13 at 20:51
  • You're welcome, glad that it worked out for you. Please consider marking it as "accepted" whenever SO lets you do so. – anubhava Sep 25 '13 at 20:55
  • `L` flag marks each rule as Last so that Apache doesn't process rest of of the rules in current pass. Having `MultiViews` enabled contradicts with mod_rewrite since Apache attempts to rewrite on its own when `MultiViews` is enabled. – anubhava Sep 25 '13 at 21:00
1

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

Crackertastic
  • 4,793
  • 1
  • 26
  • 37