0

Im trying to create pretty urls for a site im currently working on but each time i navigate to the pretty url it tells me the page dont exist, could someone take a look at my code and see what i am missing or doing wrong

I have watched tutorials and searched online for written examples which is how i come up with the code i got but i just cant seem to get it to work

Here is the code

RewriteEngine on

RewriteRule ^sub_cat/([0-9]+)/([0-9]+) view_sub_cat.php?tcid=$1&scid=$2 [NC,L]

Thanks in advance

  • think you need a `$` at the end of the pattern... ie: `^sub_cat/([0-9]+)/([0-9]+)$` – Professor Abronsius May 25 '20 at 15:15
  • tried that earlier with no result –  May 25 '20 at 15:20
  • and have you set the `RewriteBase`? – Professor Abronsius May 25 '20 at 15:23
  • yes unless i have that set wrong, i did forget to add it into my first post, it looks like this RewriteBase /forum/ the site im working on is a sub directory of the main site –  May 25 '20 at 16:35
  • Have you manually tried to GET the view_sub_cat.php URL in the browser? Does it work as expected? – hacker315 May 25 '20 at 18:50
  • Also, turn on the logging via `LogLevel alert rewrite:trace3` in .htaccess temporarily.. and get logs in apache access logs.. in `/var/log/apache2/access.log` – hacker315 May 25 '20 at 18:54
  • Example URL that you are trying to rewrite? – CBroe May 26 '20 at 07:52
  • 1
    @hacker315 if i understand correctly about manually GET the page, then yes it works correctly using the GET vars from the URL as the page works its only once i try to rewrite the URL it doesnt seem to work. I will give your second answer a shot –  May 26 '20 at 19:26
  • @CBroe check the first post at the top as i have posted the URL im trying to rewrite –  May 26 '20 at 19:27
  • It only contains your rewrite attempt. Questions of this kind should always contain a _proper_ example of a URL you want to rewrite, like `http://example.com/foo/bar` – CBroe May 27 '20 at 06:30

1 Answers1

0

Try adding these two lines of code to your .htaccess file

      RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
  • I did originally have that in my code but took it out as it made no difference –  May 25 '20 at 15:21
  • 2
    Okay try this. RewriteRule ^sub_cat/([0-9]+)/([0-9]+) ./ view_sub_cat.php?tcid=$1&scid=$2 [NC,L] –  May 25 '20 at 15:33
  • still nothing, when i use the new url which would be sub_cat/1/4 it shows my web host's default page –  May 25 '20 at 16:29