I am trying to edit my htaccess.

All urls working fine on server, but same htaccess setup redirecting category/cat_name/ url to 404 page without giving any error. all other urls working fine accept category url.

I setup my links without an id and searching urls with seo_url wich is added to database, I have checked all urls in database one by one they looks fine. Looks like problem is in my htaccess I have tried several regex typo and [L,QSA] variables too but didnt change anything. I am using wamp server and php version 7.3.0 on localhost, mod_rewrite is enabled.

I have read same questions on community sites and searched on google before asking this question none solved my problem.

My .htaccess is in root of the site

Url on browser looks fine: http://localhost/site/category/services/

My php link example :

href="category/<?php echo $row['seo_url'];?>/" title="<?php echo $row['cat_name'];?>">

My htaccess url :

RewriteRule ^category/([a-zA-Z0-9_-]+)/$ categories.php?q=$1 [L,NC] 

My codes in my categories.php

    $seourl = htmlspecialchars($_GET["q"]);
    $stmt = $pdo->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");
    if($stmt->rowCount() > 0){
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
            $ctid = intval($row['cat_id']);
            $ctname = htmlspecialchars($row['cat_name']);
            $ctseo_url = htmlspecialchars($row['seo_url']);
            $descriptions = htmlspecialchars($row['descriptions']);
            $keywords = htmlspecialchars($row['keywords']);
            $created = htmlspecialchars($row['created']);
            $img = htmlspecialchars($row['img']);
        $_SESSION['message'] = "Category not exist";    
        header("location: ../error.php");
        $_SESSION['message'] = "Category not exist";    
        header("location: ../error.php");

As you can see in code I search url with seo_url which is added to database, if there something wrong with url it should redirect me to error.php, but its redirecting to 404 page without giving an error.

all links htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^home index.php [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ detail.php?p=$1 [L,NC]
RewriteRule ^category/([a-zA-Z0-9_-]+)/$ categories.php?q=$1 [L,NC] 
RewriteRule ^contact/$ contact.php [L,NC]
RewriteRule ^forgot/$ hml.php [L,NC]
RewriteRule ^search/$ search.php [L,NC]
RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^services/$ keywords.php?q=%1 [L,NC]
RewriteRule ^kariyer-basvuru/ ik.php [L,NC]
RewriteRule ^feed/$ rss.php [L,NC]
RewriteRule ^cat-feed/$ feed.php [L,NC]
RewriteRule ^sitemap.xml$ sitemap.php [L,NC]
RewriteRule ^user/$ login.php [L,NC]
RewriteRule ^change-password/$ resetpass.php [L,NC]
RewriteRule ^Upanel/page/(.*)$ Upanel/?page=$1 [L,NC]
RewriteRule ^Upanel/page_sale/(.*)/$ Upanel/account.php?page_sale=$1 [L,NC]
RewriteRule ^Upanel/del-ilan/(.*)/$ Upanel/delil.php?id=$1 [L,NC]
RewriteRule ^Upanel/Store-edit/(.*)/$ Upanel/Sedit.php?store_id=$1 [L,NC]
RewriteRule ^Upanel/del-store/(.*)/$ Upanel/Sdel.php?store_id=$1 [L,NC]
RewriteRule ^Upanel/del-comment/(.*)/$ Upanel/Cdel.php?id=$1 [L,NC]
RewriteRule ^Upanel/opens/$ Upanel/opens.php [L,NC]
RewriteRule ^Upanel/editadds/(.*)/$ Upanel/Pedit.php?id=$1 [L,NC]
RewriteRule ^Upanel/ilanv/$ Upanel/ilanv.php [L,NC]
RewriteRule ^Upanel/profil-duzenle/(.*)/$ Upanel/profile.php?id=$1 [L,NC]
RewriteRule ^Upanel/$ Upanel/index.php [L,NC]
RewriteRule ^stores/(.*)/([a-zA-Z0-9_-]+)$ store.php?s=$1 [L,NC]
RewriteRule ^stores/$ isletmeler.php [L,NC]
ErrorDocument 404 404.shtml
  • Where on the filesystem is your .htaccess file? – MrWhite Jan 30 '19 at 12:57
  • 1
    Your .htaccess looks OK. Are you sure categories.php is not being called, just without a URL parameter? You are not seeing any redirection in the browser? (If this is all in the document root on the live site, then a redirect like ../error.php would seem to be a problem on the live site - unless you are compensating with the base tag?) – MrWhite Jan 30 '19 at 13:24
  • 1
    Try adding Options -MultiViews at the top of your .htaccess file. – MrWhite Jan 30 '19 at 15:20
  • 1
    Please include your file structure. Do you have any other .htaccess files (in subdirectories)? – MrWhite Jan 30 '19 at 15:57
  • 1
    Thanks for your effort bro it works fine know, I added solution to question. thanks again I couldn't solve the problem without your advice. I am surprised how it works fine on server but doesnt work in local. Thanks again – ismail tunahan Jan 30 '19 at 16:01

I made it work thanks adding solution if someone need it: I added MultiViews under FollowSymLinks it doesn't work on the top of the .htaccess:

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On

I changed search term q to c, it shouldn't make a difference but it does, I don't understand why anyone with knowledge can explain beter.lol.


Not the answer you're looking for? Browse other questions tagged or ask your own question.