skip to Main Content

Every single file is not found with .htaccess. Yet, I can normally access any of the files in question. Also .htaccess is in same folder as any of these files.

For example: If I enter https://example.com/post.php it works fine

But if I try with pretty link (leads to same file post.php) for example: https://example.com/vijest/slug/123 server responds with 404, file not found.

Same happens with any other pretty link, files do exit, but when accessed via .htaccess, server responds with 404.

Can you help me please?

RewriteEngine On    # Turn on the rewriting engine
<Files ~ "^.*.([Hh][Tt][Aa])">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*.(css|jpe?g|gif|png|js|ico)$ [NC]

DirectoryIndex index.php

RewriteRule    ^vijest/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)?$    post.php?idNum=$2    [NC,L]

UPDATE 1

I copied working example from same server, but other project, and it did not work… But I am 1000000000% certain that these files do exist in specified path.

2

Answers


  1. Chosen as BEST ANSWER

    So in case anyone goes through this thread, my problem was with file name. Instead of htaccess, it was named htaccesss. If you open shared screenshots you' ll be able to see.

    Thank you.


  2. You need to pass second param to .htaccess like this : post.php?idNum=$1&q=2 first param is uniqe id, second param is url string.

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^/ index.php [NC,L]
    
    RewriteRule ^vijest/([a-zA-Z0-9_-]+)$   post.php?idNum=$1 [L]
    
    RewriteRule ^vijest/(.*)/([a-zA-Z0-9_-]+)$    post.php?idNum=$1&q=2    [NC,L]
    

    Your url should be saved in db like so : how-to-create-seo-url

    and your php link should be like : <a href="vijest/<?php echo $row["news_url"];?>">See More</a>

    in post.php page : $_GET['idNum']; AND Then your query echo $_GET['idNum'];

    Here is the result : https://ibb.co/YDxQ8Mf and two parameters : https://ibb.co/XSZnSMJ

    Make sure if your post.php is in root folder with htaccess.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search