LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   mod_rewrite rule from window, now in linux not working (https://www.linuxquestions.org/questions/linux-general-1/mod_rewrite-rule-from-window-now-in-linux-not-working-770396/)

kingkashif 11-20-2009 04:03 AM

mod_rewrite rule from window, now in linux not working
 
Hello friends,

Well my website was hosted on a windows machine but now
I moved to Linux. The problem is that my rewrite rule is not working here ..

Please can anybody tell me what changes I need to make here to make it work on Linux ?

here is my rewrite rule
Quote:

RewriteRule abc-(.*)-(.*)-(.*)\.htm$ /index.php?action=$1&cat_id=$2&id=$3
RewriteRule abc-(.*)-(.*)\.htm$ /index.php?action=$1&cat_id=$2
Any help will be greatly appreciated.

Thanks,

bathory 11-20-2009 04:19 AM

Hi,

It should work. Are you sure you have "RewriteEngine on" in httpd.conf?

kingkashif 11-20-2009 04:41 AM

yes because in the same .htaccess when i put

RewriteRule ^abc-xyz$ http://yahooo.com

then it works

bathory 11-20-2009 05:03 AM

Enable rewrite logging to see what happens
Code:

RewriteLogLevel 9
RewriteLog logs/rewrite_log

Also there are a couple of things to look for:

If you copied .htaccess from the windows box, make sure it does not contain any control characters (like ^M at the end of each line).

You can try to escape the special characters in your RewriteRules and see if it works this way:
Code:

RewriteRule abc-(.*)-(.*)-(.*)\.htm$ /index.php\?action=\$1\&cat_id=\$2\&id=\$3
RewriteRule abc-(.*)-(.*)\.htm$ /index.php\?action=\$1\&cat_id=\$2


kingkashif 11-20-2009 05:17 AM

well when I put the logging tags in .htaccess file
then the site doesn't even show up.

I put it above and below "RewriteEngine On" but didn't work.


The escaping didn't work either.

you know when i try the following

Quote:

RewriteRule abc-(.*)-(.*)-(.*)\.htm$ http://yahooo.com
Then it works so I guess the problem is in this part

Code:

/index.php?action=$1&cat_id=$2&id=$3

my link is like this http://domain.com/abc-article-03432-2344.htm

So "article" should print at $1 and "03432" at $2 and "2344" at $3.

Any idea ?

bathory 11-20-2009 05:34 AM

I've tested here and it works (of course my index.php does not work with your options):
Quote:

127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (3) [perdir /usr/local/apache/htdocs/] strip per-dir prefix: /usr/local/apache/htdocs/abc-article-03432-2344.htm -> abc-article-03432-2344.htm
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (3) [perdir /usr/local/apache/htdocs/] applying pattern 'abc-(.*)-(.*)-(.*)\.htm$' to uri 'abc-article-03432-2344.htm'
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (2) [perdir /usr/local/apache/htdocs/] rewrite 'abc-article-03432-2344.htm' -> '/index.php?action=article&cat_id=03432&id=2344'
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (3) split uri=/index.php?action=article&cat_id=03432&id=2344 -> uri=/index.php, args=action=article&cat_id=03432&id=2344
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (3) [perdir /usr/local/apache/htdocs/] applying pattern 'abc-(.*)-(.*)\.htm$' to uri '/index.php'
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#8468b18/initial] (1) [perdir /usr/local/apache/htdocs/] internal redirect with /index.php [INTERNAL REDIRECT]
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#846ce40/initial/redir#1] (3) [perdir /usr/local/apache/htdocs/] strip per-dir prefix: /usr/local/apache/htdocs/index.php -> index.php
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#846ce40/initial/redir#1] (3) [perdir /usr/local/apache/htdocs/] applying pattern 'abc-(.*)-(.*)-(.*)\.htm$' to uri 'index.php'
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#846ce40/initial/redir#1] (3) [perdir /usr/local/apache/htdocs/] strip per-dir prefix: /usr/local/apache/htdocs/index.php -> index.php
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#846ce40/initial/redir#1] (3) [perdir /usr/local/apache/htdocs/] applying pattern 'abc-(.*)-(.*)\.htm$' to uri 'index.php'
127.0.0.1 - - [20/Nov/2009:13:29:30 +0200] [localhost/sid#81f24e0][rid#846ce40/initial/redir#1] (1) [perdir /usr/local/apache/htdocs/] pass through /usr/local/apache/htdocs/index.php
You should put the Rewritelog directives in httpd.conf to enable mod_rewrite logging

kingkashif 11-20-2009 05:51 AM

you know when I put my domain in that rule then it works for example

Code:


RewriteRule abc-(.*)-(.*)-(.*)\.htm$ http://domain.com/index.php?action=$1&cat_id=$2&id=$3

So what is wrong here ?

Why when i put my domain in the rule then it works and when i don't put my domain then it doesn't work... :(

kingkashif 11-20-2009 06:02 AM

ok got it ..

My files are here http://ip/~user/

so I had to put my rule like following

[code]
RewriteRule abc-(.*)-(.*)-(.*)\.htm$ /~user/index.php?action=$1&cat_id=$2&id=$3
[code]


Thanks Bathory For your help :)


All times are GMT -5. The time now is 01:30 PM.