LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-20-2009, 04:03 AM   #1
kingkashif
Member
 
Registered: May 2009
Posts: 92

Rep: Reputation: 16
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,
 
Old 11-20-2009, 04:19 AM   #2
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,905

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Hi,

It should work. Are you sure you have "RewriteEngine on" in httpd.conf?
 
Old 11-20-2009, 04:41 AM   #3
kingkashif
Member
 
Registered: May 2009
Posts: 92

Original Poster
Rep: Reputation: 16
yes because in the same .htaccess when i put

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

then it works
 
Old 11-20-2009, 05:03 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,905

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
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
 
Old 11-20-2009, 05:17 AM   #5
kingkashif
Member
 
Registered: May 2009
Posts: 92

Original Poster
Rep: Reputation: 16
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 ?
 
Old 11-20-2009, 05:34 AM   #6
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,905

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
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
 
Old 11-20-2009, 05:51 AM   #7
kingkashif
Member
 
Registered: May 2009
Posts: 92

Original Poster
Rep: Reputation: 16
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...

Last edited by kingkashif; 11-20-2009 at 05:57 AM.
 
Old 11-20-2009, 06:02 AM   #8
kingkashif
Member
 
Registered: May 2009
Posts: 92

Original Poster
Rep: Reputation: 16
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unusual apache mod_rewrite rule entz Linux - Server 1 10-04-2009 09:48 AM
Help with mod_rewrite - [L] not working MicahCarrick Programming 0 05-08-2008 08:12 PM
Apache2 mod_rewrite rule for changing file extentions CyberDog3K Linux - Server 0 08-27-2007 01:25 AM
mod_rewrite - rule to change http to https Firebar Linux - Server 10 06-05-2007 07:29 AM
mod_rewrite rule question jmoschetti45 Linux - Software 0 03-19-2007 07:29 PM


All times are GMT -5. The time now is 08:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration