This is the first time I have ever tried to use mod_rewrite and have been stuck for a couple days. I am trying to change

to

Is this even achievable? Any advice will be very much appreciated!

Dani AI

Generated

Short summary and practical fix for the thread: turning
/www.mysite.com/example6.php?id=games
into
/www.mysite.com/example6/games
is straightforward with mod_rewrite. As showed the existing query URLs and as suggested, the important bits are (a) where the .htaccess lives, (b) that mod_rewrite is actually honored by Apache (AllowOverride), and (c) avoiding side effects like MultiViews.

Example rules (two common placements)

  • .htaccess in the document root — capture the pretty path from REQUEST_URI and pass it as the id parameter:
    
    # placed in the site root
    Options -MultiViews
    RewriteEngine On
    RewriteBase /

RewriteCond %{REQUESTURI} ^/example6/([A-Za-z0-9-]+)/?$
RewriteRule .* /example6.php?id=%1 [L,QSA,NC]


- .htaccess inside the example6 directory — pattern is relative to that folder:
```apache
# placed in /example6/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /example6/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_-]+)/?$ example6.php?id=$1 [L,QSA,NC]

Quick troubleshooting checklist (common causes found in hosts and shared setups)

  • Confirm mod_rewrite is loaded and Apache honors .htaccess (Ask host or check httpd.conf for AllowOverride All).
  • Test .htaccess is being read by adding a temporary rule that issues a visible redirect (e.g., map ^rewrite-test$ to example6.php?id=rewrite-test with [R]).
  • Turn off MultiViews (Options -MultiViews) — it often conflicts with pretty URLs.
  • Use QSA to preserve extra query parameters; test with a 302 redirect first, then switch to 301 for SEO.
  • Check Apache error log for syntax errors or rewrite loops.

If legacy query URLs should redirect to the pretty form (SEO-friendly canonicalization), add a rule that detects requests for example6.php?id=... and issues an external redirect to /example6/<id> (use a 302 while testing, then 301). This approach avoids changing example6.php logic while presenting clean URLs.

Recommended Answers

All 5 Replies

I have searched this forum and have done extensive google search and have not been able to figure it out. I have many links that look like:



I have tried lots of different code putting this in my .htaccess file:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]

and

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>

and many more attempts but nothing works to get my URLS to look like this:



I do have mod_rewrite enabled on my server. Does anyone have any ideas? Thanks in advance.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^example6/([^/]+)$ example6.php?id=$1 [L]

Does that work? Haven't tested it so I might of forgotten something. Just wrote it from memory.

No, I have also tried

RewriteRule ^(.*?)/(.*) example6.php?id=$1&id2=$2

and

RewriteRule ^example6/(.*)$ /example6.php?id=$1 [L]

Does it matter where I upload my .htaccess file to? Thanks much

I would say just putting it in the document root would be ideal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.