k961
k961

Reputation: 587

apache mod_rewrite is not working completely

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

Upvotes: 0

Views: 28

Answers (1)

anubhava
anubhava

Reputation: 785128

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.

Upvotes: 1

Related Questions