1

What I want is a Wordpress type of URL rewrite.

What I have now is:

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ rewrite.php?data=$1 [L,QSA]

This almost works rewriting everything except existing files (css,js etc files are not rewritten as expected).

The problems I have with this are:

  1. .css, .js, Image and PHP files are also accessible by entering their file name. eg.: domain.com/style.css will be accessible by anyone.

  2. I want some existing files(only php right now) to be redirected anyway. eg.: domain.com/movies.php should redirect to rewrite.php(include 404.php) and domain.com/movies or domain.com/movies/ would include movies.php page.

Ideally I would also be able to change user entered URL from domain.com/movies to domain.com/movies/ for consistency more than anything else.

I want to keep .htaccess to a bare minimum. Does wordpress rewrite everything including .css files?

What I want:

  1. Some php files to redirect others not. eg: includes/func.inc.php should not be accessible to the users, while movies.php should be accessible but ONLY from this url domain.com/movies/

(not essential)

  1. Change url to canonical url eg: domain.com/movies to
    domain.com/movies/ (some resources on how to achieve this would be
    nice). Note: domain.com/movies url should still work but appear with a slash at the end either via rewrite or maybe by just adding a slash with javasript (faster?)

  2. Make .css/.js files inaccessible by the user. eg: domain.com/style.css should redirect the user to a 404 page

Charles
  • 50,943
  • 13
  • 104
  • 142
DominicM
  • 6,520
  • 13
  • 39
  • 60
  • 3
    The rule you have now shouldn't rewrite urls for your css/javascript files since you have a `! -f` in your RewriteCond. Are you finding that it does anyways? – Eric Petroelje Jan 02 '13 at 15:39
  • No, it doesn't, what I want is to make these files inaccessible via url (not essential) and have some php files/page redirected but not inlude files or few other php files. – DominicM Jan 02 '13 at 15:41
  • 1
    @EricPetroelje: While working on the formatting of the question I asked myself exactly the same. Also: You could check that things are not a directory and link as well (the later is missed by Wordpress IIRC) *and* the slash at the end is called canonical URLs / directories, you can read about that in the Apache documentation, there are different ways / settings / directives to deal with that, so this must not be done within the rewrite module. – hakre Jan 02 '13 at 15:42
  • @DominicM: Your comment does not make it any clearer for me. Can you please elaborate what you want with the `.css` files to happen? And when you write *redirect* what do you mean? A URL-Rewrite or the technical HTTP redirect that is communicating with the browser telling where to go instead? – hakre Jan 02 '13 at 15:43
  • Ok, what I want to happen to css/js and php includes is to redirect them to 404 page when accessed by the user(this is not essential). As for movies.php I want it accessible only by domain.com/movies/. By redirect I mean URL-Rewrite. – DominicM Jan 02 '13 at 15:46
  • @hakre I omitted directory check as I do not want users to be able to access /browse files on the server. What do you mean by link? do you just mean absolute links(not external server). If so that may actually work if I change all site url's to absolute url's but I don't know if that's possible work... – DominicM Jan 02 '13 at 16:16
  • I read 404, maybe this QA material is of use to you: [Requests to .htaccess should return 404 instead of 403](http://stackoverflow.com/q/7945795/367456) - it shows how you can turn certain requests into 404s in apache. This works as well via the rewrite module by using the `R` (Redirect) flag. – hakre Jan 02 '13 at 16:18
  • Problem with that is it's apache based solution and I know very little about it which is why I want very little in my .htaccess file :) – DominicM Jan 02 '13 at 16:25
  • If you want to get minimal, turn off the computer. That works best, always. And there is not much to do for. ;) – hakre Jan 02 '13 at 16:25
  • thats too minimal :), I was hoping to get same/similar solution to wordpress implementation of url rewrite... – DominicM Jan 02 '13 at 16:27

0 Answers0