3
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by Isaac_4
0

already but have not been able to help me give you the example of

Edited by bro_1

0

Well, the .htaccess that I use is usually something like:

RewriteEngine on

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

This redirects everything to index.php. You can then use PHP to read the query string ($_SERVER['REQUEST_URI'] and other $_SERVER vars) and include the appropriate files. This .htaccess setup works like a charm for me.

I think for your specific case something like RewriteRule media\?.* media.php?$1 should also do the trick. But then again, the last time I wrote a .htaccess file is years ago so I cannot be so sure :p.

Edited by minitauros

1

You need to define what you want to redirect from as well as what you want to redirect to. Assuming that you want to go from:

http://example.com/test

to:

http://example.com/media.php?page=test

Then this should do the trick:

<IfModule mod_rewrite.c>
    # Turn on the engine
    RewriteEngine On

    # If your pages are under the root of the domain, leave as /
    # If they are instead under a subdirectory such as /test/,
    # change RewriteBase to be /test/
    RewriteBase /

    # Don't redirect real files (-f) or directories (-d)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Do the redirect - if you had to change RewriteBase, add that
    # here as well - /test/media.php instead of /media.php
    RewriteRule ^(.*)$ /media.php?page=$1 [L]
</IfModule>

But if your situation is more complex, this won't cut it:

  • Do some URLs need to be redirected to files other than media.php?
  • Are there multiple base directories to redirect from (not just / or /test/ as in my comments, but more than one base)?
  • Do you need query strings to still work? (as is, in the URL http://example.com/test?q=1 the q=1 value will be stripped out and won't be visible to media.php)

Edited by Isaac_4

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.