0

Please before u say its duplicated i know i have googled for hours but i dont know where the problem is i have a centos server with

Server version: Apache/2.2.27 (Unix)
Server built:   Jul 26 2015 04:33:04

files are located in :

/home/user/public_html

ls -la:

index.php includes view.php .htaccess ...

when i try to open webpage site.com/view/test i do

tail -f /var/log/httpd/error_log

but there is no error

this is my rules

RewriteEngine on
RewriteBase /
RewriteRule ^view/$ view.php
RewriteRule ^view$ view.php
RewriteRule ^view/(\w+)?$ view.php?cat=$1

it works fine on localhost (ubuntu 14.04 Desktop).

On server when i access

site.com/view

its fine and shows me view.php but

site.com/view/test

will not give me view.php?cat=test

k961
  • 577
  • 1
  • 5
  • 19
  • 1
    Multiviews, Path info? Compare error and access.log, or enable the RewriteLog for diagnosis. – mario Sep 19 '15 at 04:31
  • @mario i added some more info also there is a suphp 0.7.1 – k961 Sep 19 '15 at 04:38
  • Not relevant. See http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained for "pitfalls". Show the rewrite.log, when you can't be more precise than "will not give me". – mario Sep 19 '15 at 04:44

1 Answers1

1

Your regex seems to be a problem as you have (\w+)? after view/ in last rule causing ^view/$ rule to match first always as it is placed before ^view/(\w+)? rule.

Try these rules:

Options -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^view/?$ view.php [L,NC]
RewriteRule ^view/(\w+)/?$ view.php?cat=$1 [L,QSA,NC]

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

anubhava
  • 761,203
  • 64
  • 569
  • 643