1

I have browsed the other topics, including this one: Mod_rewrite invisibly: works when target is a file, not when it's a directory, but I can't find a solution to my problem.

I have the following rewriting rule:

RewriteRule ^([a-zA-Z0-9_-]+)$ ./index.php?s=$1 [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ ./index.php?s=$1 [L,NC]

What it does is to write anything like http://myaddress/parameter to http://myaddress/index.php?s=parameter and show this new rewritten address in the browser's address bar.

How can I make rewriting without showing the rewritten URL in the address bar?


Edit

This is the content of my .htaccess file:

DirectoryIndex index.php

RewriteEngine On

RewriteRule ^([a-z0-9_\-]+)/?$ index.php?s=$1 [L,NC,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?$ index.php?u=$1&s=$2 [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?$ index.php?u1=$1&u2=$2&s=$3 [L,NC]
Community
  • 1
  • 1
AntonioJunior
  • 919
  • 2
  • 15
  • 32

2 Answers2

1

This should work:

RewriteEngine On

RewriteRule ^([-a-zA-Z0-9_]+)$ index.php?s=$1 [L]
RewriteRule ^/?$ index.php [L]
Matt
  • 1,151
  • 3
  • 13
  • 34
  • It still doesn't work. It keeps showing the rewritten URL in the address bar. I have edited my post to show the rewriting rules. – AntonioJunior Aug 14 '11 at 04:30
1

1. No need for 2 rules that do the same job (the only difference is presence of trailing slash).

2. No need to have a-zA-Z in pattern if you have [NC] flag -- a-z is enough.

3. Try rule without ./

Considering all the above mentioned the rule will become:

RewriteRule ^([a-z0-9_\-]+)/?$ index.php?s=$1 [L,NC,QSA]

P.S. I have also added the QSA flag to preserve original query string (if present).

The rule is tested and is working fine. If it still does not work for you then post ALL rewrite rules that you have.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Thanks, but it still doesn't work, I have edited my question to post the rewrite rules that I have. – AntonioJunior Aug 14 '11 at 04:31
  • @AntonioJunior Sorry, but there is NO way that THESE rules will do a redirect (URL changes in browser). If you can edit server config then enable rewrite debugging (`RewriteLogLevel 9`), restart Apache, try this problematic URL and check the rewrite log -- it should tell you what is going on. Maybe it is your PHP code that does redirect -- to check create empty PHP file and use it instead of index.php in rewrite rules. I would also suggest to **clear browser cache** or try another browser ... as modern browsers do cache redirects. – LazyOne Aug 14 '11 at 08:23
  • Hi, LazyOne, thank you so much! In fact, I was doing a redirect in the PHP code and I didn't remember that until you pointed it out. Thanks for the patience in explaining. – AntonioJunior Aug 14 '11 at 15:53