0

I need to convert a link that contains php variables into a clean link that can be picked up and indexed by Google. I've looked at ways to do this, and using mod_rewrite apparently is the best way to handle this.

Currently my URLs look like this:

 http://mysite.com/jobs/view/?j=senior-model-validator-groep-risk-management

I'd like to end up looking like this

http://mysite.com/jobs/view/senior-model-validator-groep-risk-management

It's probably really easy but sadly I know nothing about .htaccess. I tried a few things but I end up with nothing remotely close :-)

Thanks in advance!

Edit: Here's my full .htaccess file based on the help so far:

<IfModule mod_rewrite.c>  
RewriteEngine On  
RewriteRule ^jobs/view/(.*)$   jobs/view/?j=$1 [L]  
RewriteBase /  
RewriteRule ^index\.php$ - [L]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . /index.php [L]  
</IfModule>  
2
  • 1
    Is /jobs/view/ a directory on the server with an index.php? Commented Jun 19, 2012 at 13:35
  • No it is not. it's a virtual directory. The url is based on a WordPress page that uses the variable to display the content. the actual .htaccess page is located in the root folder of the site Commented Jun 19, 2012 at 13:40

1 Answer 1

1

You may use an .htaccess file at the root of you web site with these rules:

RewriteEngine on
RewriteRule ^jobs/view/(.*)$   jobs/view/?j=$1 [L]

Do not forget to filter/validate GET input in the script dealing with the data...

Sign up to request clarification or add additional context in comments.

4 Comments

You may need to be more precise in the rule, such as: RewriteRule ^jobs/view/([a-zA-Z0-9\-]+)$ jobs/view/?j=$1 [L]
I've updated the original post in what I have right now based on your answer.. The comment section borked my formatting :-)
The rule I gave you must be positioned at the end of the rules in your .htaccess file, that is to say just before </IfModule>.
@Benoit If it's at the end, then it won't get redirected because of the current last rule, which is also Last. So, I'd say the OP has to insert your rule just before his current last one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.