Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
mod_rewrite Clean URL rewriting

I'm trying to write clean url's for my website. I'm a rookie at this so forgive me. My .htaccess file currently looks like this:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)$ something.php?query=$1
RewriteRule ^([a-zA-Z0-9-]+)/$ something.php?query=$1

The first rule seems to work. For example website.com/good-looking-query-string does in fact rewrite to website.com/something.php?query=ugly+looking+query+string

The second rule is where I'm having a problem. I can't get that trailing slash to work. For example website.com/good-looking-query-string/ appears to pull up the page but without any CSS rules applied. I noticed all the links end up appended to the query string also. For example the link back to index.php ends up like website.com/good-looking-query-string/index.php

I need to get that trailing slash to work. What in the world am I doing wrong?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can combine two line in one line:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)/?$ something.php?query=$1

In this case / will be optional

over 4 years ago · Santiago Trujillo Report

0

Your issue is client side, you are using relative paths but you need to be using Root-relative paths. A URL of:

website.com/good-looking-query-string

loads from the root. A url of:

website.com/good-looking-query-string/

loads from the good-looking-query-string directory.

So instead of href="style.css" you should have "href="/style.css"and the index issue should behref="/index.php"instead ofhref="index.php"`.

As noted in the earlier comment your regex could be simplified by adding a ? on the trailing slash to make it option. That is not your issue though, just simplifies the rules.

RewriteRule ^([a-zA-Z0-9-]+)/?$ something.php?query=$1
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!