skip to Main Content

I’m currently attempting to rewrite URLS for my employer’s website for hopefully better results in SEO. However, I can’t seem to get the url rewrite to work.

I have used this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^myemployerssite.com.au$
RewriteRule (.*) https://www.myemployerssite.com.au/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 https://www.myemployerssite.com.au/page-not-found.php
RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
</IfModule>

I expected, for example, the first service page which is civil construction to have it’s URL to be rewritten from https://www.myemployerssite.com.au/services.php?serviceid=1 to https://www.myemployerssite.com.au/services/civil-construction

But the URL remains as https://www.myemployerssite.com.au/services.php?serviceid=1

The redirect from non-www to www is working as intended as is the redirect from to http to https.

Some advice would be appreciated

2

Answers


  1. I changed the order of the rules:

    <IfModule mod_rewrite.c>
    
      RewriteEngine On
    
      RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
    
      RewriteCond %{HTTP_HOST} ^myemployerssite.com.au$
      RewriteRule (.*) https://www.myemployerssite.com.au/$1 [R=301,L]
    
      RewriteCond %{SERVER_PORT} !^443$
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    </IfModule>
    
    ErrorDocument 404 /page-not-found.php
    
    Login or Signup to reply.
  2. Try changing this line

    RewriteRule ^services/civil-construction$ /services.php?serviceid=1 [L]
    

    to

    RewriteCond %{QUERY_STRING} serviceid=1$
    RewriteRule ^services.php$ /services/civil-construction [L,R]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search