[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

.htaccess rewrite url with querystring problem

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
der_23
Asked:
der_23
  • 6
  • 5
1 Solution
 
Lucas BishopClick TrackerCommented:
The htaccess file wasn't attached.
0
 
Steve BinkCommented:
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
 
der_23Author Commented:
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
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
der_23Author Commented:
Would it be possible for you to write out the rule for me here?
0
 
Steve BinkCommented:
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
 
der_23Author Commented:
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
 
Steve BinkCommented:
Does it say anything else besides "error"?
0
 
der_23Author Commented:
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
 
Steve BinkCommented:
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
 
der_23Author Commented:
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
 
der_23Author Commented:
I finally move the mobile redirect above the other rewriterule and it worked
0
 
Steve BinkCommented:
#41758833 and #41760560 provided the solution here.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now