Solved

.htaccess rewrite url with querystring problem

Posted on 2016-08-16
13
144 Views
Last Modified: 2016-08-22
Hi,

This is how I am currently redirecting the URL from PC to mobile at the moment.

RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [R=301,L]

The problem with the above code is that it cuts ? all querystring out when redirecting to the mobile URL

Now this won't have a problem when rewriting URL from http://www.localjobboard.com/bangkok/ (originally http://www.localjobboard.com/jobs-list-province.php?p_name=bangkok) to http://m.localjobboard.com/bangkok/

But it will have problem with URL that requires sending over the querystring, for example:
http://www.localjobboard.com/keyword-search.php?s_keyword=analyst is redirecting to http://m.localjobboard.com/keyword-search.php instead of http://m.localjobboard.com/keyword-search.php?s_keyword=analyst

So I tried to solve the problem by using this code

RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [QSA,R=301,L]

Or this code

RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI} [R=301,L]

when I use the above code, it has problem with redirecting
http://www.localjobboard.com/bangkok/ in goes to: http://m.localjobboard.com/bangkok/?p_name=bangkok instead.


How do i rewrite so that
http://www.localjobboard.com/bangkok/ goes to http://m.localjobboard.com/bangkok/ and
http://www.localjobboard.com/keyword-search.php?s_keyword=analyst goes to http://m.localjobboard.com/keyword-search.php?s_keyword=analyst

Please see the attached htaccess file for more info. Thank you for your help.
0
Comment
Question by:der_23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
13 Comments
 
LVL 18

Expert Comment

by:Lucas Bishop
ID: 41758515
The htaccess file wasn't attached.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 41758731
You would need two different rule sets.  One rule set would be your current set to handle the "general" case - remove the query string.  The second, new rule set would remove the '?' at the end of the rule and add the [QSA] modifier.  This rule set should appear *before* your current rule set, and limit itself to act only on URLs requiring the query string (e.g., your search page).
0
 

Author Comment

by:der_23
ID: 41758815
here's the htaccess code

#Redirect to www location
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^localjobboard.com [nc]
rewriterule ^(.*)$ http://www.localjobboard.com/$1 [r=301,nc]
 
 
rewriterule ^งาน/(.*),(.*)/$ /jobs-list-department.php?s_jobtype=$1&s_jobtype_text=$2
rewriterule ^งาน/(.*),(.*)/page-(.*).html /jobs-list-department.php?s_jobtype=$1&s_jobtype_text=$2&page=$3
rewriterule ^หางาน/(.*),(.*)/$ /jobs-list-province.php?s_province=$1&s_province_text=$2
rewriterule ^หางาน/(.*),(.*)/page-(.*).html /jobs-list-province.php?s_province=$1&s_province_text=$2&page=$3
rewriterule ^ประกาศงาน/(.*),(.*)/$ /jobs-list-business.php?s_business=$1&s_business_text=$2
rewriterule ^ประกาศงาน/(.*),(.*)/page-(.*).html /jobs-list-business.php?s_business=$1&s_business_text=$2&page=$3
rewriterule ^สมัครงาน/(.*),(.*)/$ /job-detail.php?job_id=$1&job_text=$2
rewriterule ^รับสมัครงาน/(.*),(.*)/$ /jobs-list-company.php?hotel_id=$1&hotel_name=$2
rewriterule ^บทความ/$ /article.php
rewriterule ^บทความ/(.*)-(.*)/$ /article-detail.php?id=$1&title=$2
 
rewriterule ^(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)$ /jobs-list-province.php?p_name=$1
rewriterule ^(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/page-(.*)$ /jobs-list-province.php?p_name=$1&page=$2
 
rewriterule ^(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/$ /jobs-list-province.php?p_name=$1
rewriterule ^(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/page-(.*)/$ /jobs-list-province.php?p_name=$1&page=$2
 
rewriterule ^(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)$ /jobs-list-department.php?t_name=$1
rewriterule ^(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/page-(.*)$ /jobs-list-department.php?t_name=$1&page=$2
 
rewriterule ^(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/$ /jobs-list-department.php?t_name=$1
rewriterule ^(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/page-(.*)/$ /jobs-list-department.php?t_name=$1&page=$2
 
 
 
rewriterule ^(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)$ /jobs-list-business.php?b_name=$1
rewriterule ^(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/page-(.*)$ /jobs-list-business.php?b_name=$1&page=$2
 
rewriterule ^(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/$ /jobs-list-business.php?b_name=$1
rewriterule ^(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/page-(.*)/$ /jobs-list-business.php?b_name=$1&page=$2
 
 
 
 
 
 
 
 
rewriterule ^en/งาน/(.*),(.*)/$ /en/jobs-list-department.php?s_jobtype=$1&s_jobtype_text=$2
rewriterule ^en/งาน/(.*),(.*)/page-(.*).html /en/jobs-list-department.php?s_jobtype=$1&s_jobtype_text=$2&page=$3
rewriterule ^en/หางาน/(.*),(.*)/$ /en/jobs-list-province.php?s_province=$1&s_province_text=$2
rewriterule ^en/หางาน/(.*),(.*)/page-(.*).html /en/jobs-list-province.php?s_province=$1&s_province_text=$2&page=$3
rewriterule ^en/ประกาศงาน/(.*),(.*)/$ /en/jobs-list-business.php?s_business=$1&s_business_text=$2
rewriterule ^en/ประกาศงาน/(.*),(.*)/page-(.*).html /en/jobs-list-business.php?s_business=$1&s_business_text=$2&page=$3
rewriterule ^en/สมัครงาน/(.*),(.*)/$ /en/job-detail.php?job_id=$1&job_text=$2
rewriterule ^en/รับสมัครงาน/(.*),(.*)/$ /en/jobs-list-company.php?hotel_id=$1&hotel_name=$2
 
rewriterule ^en/(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)$ /en/jobs-list-province.php?p_name=$1
rewriterule ^en/(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/page-(.*)$ /en/jobs-list-province.php?p_name=$1&page=$2
 
rewriterule ^en/(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/$ /en/jobs-list-province.php?p_name=$1
rewriterule ^en/(abroad|allarea|krabi|bangkok|kanchanaburi|kalasin|kamphaengphet|khonkaen|chanthaburi|chachoengsao|chonburi|chainat|chaiyaphum|chumphon|trang|trat|tak|nakhonnayok|nakhonpathom|nakhonphanom|korat|nakhonsithammarat|nakhonsawan|nonthaburi|narathiwat|nan|bungkan|buriram|pathumthani|prachuap|prachinburi|pattani|ayutthaya|phayao|phangnga|phatthalung|phichit|phitsanulok|phuket|mahasarakham|mukdahan|yala|yasothon|roiet|ranong|rayong|ratchaburi|lopburi|lampang|lamphun|sisaket|sakonnakhon|songkla|satun|samutprakarn|samutsongkhram|samutsakhon|saraburi|sakaeo|singburi|suphanburi|suratthani|surin|sukhothai|nongkhai|nongbualamphu|angthong|amnatcharoen|udonthani|uttaradit|uthaithani|ubon|chiangrai|chiangmai|phetchaburi|phetchabun|loei|phrae|maehongson)/page-(.*)/$ /en/jobs-list-province.php?p_name=$1&page=$2
 
rewriterule ^en/(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)$ /en/jobs-list-department.php?t_name=$1
rewriterule ^en/(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/page-(.*)$ /en/jobs-list-department.php?t_name=$1&page=$2
 
rewriterule ^en/(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/$ /en/jobs-list-department.php?t_name=$1
rewriterule ^en/(legal|marketing|hotel|agriculture|sales|engineering-design|logistics|it|advertising|parttime|admin|safety|technicians|writer|entertainment|import-export|service|account|hr|factory|manager|hospital|housekeeper|security|research|productions|sales-engineer|electrical|architect|engineer|messenger|media|health|textile|design|jewelry|education|restaurant|credit-collection|secretary|economics|others)/page-(.*)/$ /en/jobs-list-department.php?t_name=$1&page=$2
 
 
rewriterule ^en/(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)$ /en/jobs-list-business.php?b_name=$1
rewriterule ^en/(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/page-(.*)$ /en/jobs-list-business.php?b_name=$1&page=$2
 
rewriterule ^en/(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/$ /en/jobs-list-business.php?b_name=$1
rewriterule ^en/(construction|agricultural|printmedia|school|transportation|directsales|technology|shop|cosmetics|adagency|finance|tourism|consulting|recruitment|banks|intertrade|serviceindustry|showbusiness|insurance|energy|commerce|furniture|cleaning|medical|healthcare|hospitality|spa|credit|massmedia|law|realestate|interiordesign|restaurant|stationary|chemical|machinery|packaging|electrical|vehicle|garment|steel|electronics|jewellery|gov|unclassified)/page-(.*)/$ /en/jobs-list-business.php?b_name=$1&page=$2
 
 
 
ErrorDocument 404 http://www.localjobboard.com/
 
## SITE REFERRER BANNING
RewriteCond %{HTTP_REFERER} yourserverisdown.com [NC,OR]
RewriteCond %{HTTP_REFERER} yourserverisdown.com
RewriteRule .* - [F]
 
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
    RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
    RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
 
    # Check if mobile=0 is set and set cookie 'mobile' equal to 0
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
 
    # cookie can't be set and read in the same request so check
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [S=1]
 
    # Check if this looks like a mobile device
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
    RewriteCond %{HTTP:Profile}       !^$
 
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST}          !^m\.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
 
               
    # Now redirect to the mobile site
    RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [R=301,L]

Open in new window

0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

Author Comment

by:der_23
ID: 41758816
Would it be possible for you to write out the rule for me here?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 41758833
I assume you are talking about line 107.  Here's how you would implement this:
RewriteRule ^/?keyword-search\.php$ http://m.localjobboard.com%{REQUEST_URI} [R=301,L,QSA]
RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [R=301,L]

Open in new window


If you wanted more page than just keyword-search.php to use this same strategy, add additional rules to handle them.
0
 

Author Comment

by:der_23
ID: 41758968
Nope this doesn't work, it gives error.

RewriteRule ^/?keyword-search\.php$ http://m.localjobboard.com%{REQUEST_URI} [R=301,L,QSA]
RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [R=301,L]

Open in new window

0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 41759695
Does it say anything else besides "error"?
0
 

Author Comment

by:der_23
ID: 41760517
I tested with this url http://www.localjobboard.com/keyword-search.php?s_keyword=architect

test1.gif
Please see error above.

but when I remove

RewriteCond %{HTTP_HOST}          !^m\.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
    # Now redirect to the mobile site 

Open in new window


it is redirecting fine
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 41760560
The two RewriteCond lines actually belong to the original rule.  Move the new rule above them.  You want to duplicate those lines for the new rule, as well.  They will prevent an infinite redirect.

Try changing the second RewriteCond line to:
RewriteCond %{HTTP_COOKIE} !mobile=0(;|$) [NC]

Open in new window

0
 

Author Comment

by:der_23
ID: 41760578
sorry but I still don't get it, how should the code be? Please help to correct this.

# Check if mobile=1 is set and set cookie 'mobile' equal to 1
    RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
    RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
 
    # Check if mobile=0 is set and set cookie 'mobile' equal to 0
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
 
    # cookie can't be set and read in the same request so check
    RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
    RewriteRule ^ - [S=1]
 
    # Check if this looks like a mobile device
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
    RewriteCond %{HTTP:Profile}       !^$
 
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST}          !^m\.
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
 
               
    # Now redirect to the mobile site
    RewriteRule ^/?keyword-search\.php$ http://m.localjobboard.com%{REQUEST_URI} [R=301,L,QSA]
    RewriteRule ^ http://m.localjobboard.com%{REQUEST_URI}? [R=301,L]

Open in new window

0
 

Author Comment

by:der_23
ID: 41762251
I finally move the mobile redirect above the other rewriterule and it worked
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 41762548
#41758833 and #41760560 provided the solution here.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

615 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