mod_rewrite not redirecting!

Posted on 2008-11-14
Last Modified: 2013-12-09
RewriteEngine On
RewriteRule   ^/automobiles(/)$             /index.php?view=autos             [R=301,NC,QSA,L]

This should take and point it to, no?
Question by:trickyidiot
    LVL 27

    Expert Comment

    in httpd.conf
    RewriteEngine On
    RewriteRule   ^/automobiles/?$             /index.php?view=autos             [R=301,NC,QSA,L]

    or in .htaccess files:

    RewriteEngine On
    RewriteRule   ^automobiles/?$             /index.php?view=autos             [R=301,NC,QSA,L]

    /? stands for 0 or 1 slash. If you don't want an external redirect, drop "R=301," from the flags

    LVL 6

    Author Comment

    Got a big fat internal server error on that one

    here's the full set of code from httpd.conf:
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    		<IfModule mod_rewrite.c>
    			RewriteEngine On
    			RewriteCond   %{REQUEST_FILENAME} !-f
    			RewriteCond   %{REQUEST_FILENAME} !-d
    			#RewriteRule   ^/automobiles/?$ 			/index.php?view=autos 		[NC,L]
    			#RewriteRule   ^/computing/?$ 				/index.php?categoryID=2953 	[NC,L]
    			#RewriteRule   ^/electronics/?$ 			/index.php?categoryID=2721 	[NC,L]
    			#RewriteRule   ^/mac/?$ 					/index.php?categoryID=2720 	[NC,L]
    			#RewriteRule   ^/memory/?$ 					/index.php?categoryID=5013 	[NC,L]
    			#RewriteRule   ^/mobilecomputing/?$ 		/index.php?categoryID=2719 	[NC,L]
    			#RewriteRule   ^/officesupplies/?$ 			/index.php?categoryID=3816 	[NC,L]
    			#RewriteRule   ^/traveler/?$ 				/index.php?view=traveler 	[NC,L]
    			RewriteRule   ^(.*)$ /index.php?action=OldLinkConversion&queryString=$1 [QSA,L]

    Open in new window

    LVL 6

    Author Comment

    I have the rules commented out as they caused the internal server error
    LVL 27

    Accepted Solution

    That is directory context. I'd suggest - if possible - to place the rules outside of the <Directory> section with (code below). That would avoid internal redirects.

    The rules are/were not the origin of the problem, but the conditions are on a wrong place. The order of processing is always rule-pattern --> condition(s) --> substitution. So the conditions above a rule are only applied for this specific rule, not for all rules below.
                            RewriteEngine On
                            RewriteRule   ^/automobiles/?$                         /index.php?view=autos           [NC,L]
                            RewriteRule   ^/computing/?$                           /index.php?categoryID=2953      [NC,L]
                            RewriteRule   ^/electronics/?$                         /index.php?categoryID=2721      [NC,L]
                            RewriteRule   ^/mac/?$                                         /index.php?categoryID=2720      [NC,L]
                            RewriteRule   ^/memory/?$                                      /index.php?categoryID=5013      [NC,L]
                            RewriteRule   ^/mobilecomputing/?$             /index.php?categoryID=2719      [NC,L]
                            RewriteRule   ^/officesupplies/?$                      /index.php?categoryID=3816      [NC,L]
                            RewriteRule   ^/traveler/?$                            /index.php?view=traveler        [NC,L]
                            RewriteCond   %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
                            RewriteCond   %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
                            RewriteRule   ^(.*)$ /index.php?action=OldLinkConversion&queryString=$1 [QSA,L]

    Open in new window

    LVL 6

    Author Closing Comment

    nail, head, some smashing involved - good carpenter.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    footer widgets not floating nicely 12 39
    Web Site Hosting 10 54
    erros on link  checking 2 24
    WCAG audit tools 1 39
    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now