[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Help me get a really simple mod_rewrite to work?

I am trying to create a Rewrite Rule in htaccess that will take a url such as
http://www.myplace.com/vwxyz

and rewrite it to

http://www.myplace.com/index.php/?cx=vwxyz

My server has recently been upgraded from Apache to LiteSpeed but according to the documentation it uses standard htaccess files (but without a performance hit)

The entire contents of the .htaccess file is as follows:

RewriteEngine on
RewriteRule ^c/([^/\.]+)/?$ index.php?cx=$1 [L]

and I've tried it both in the root and in the public_html directory.

What I get is

 404 Not Found
The resource requested could not be found on this server! Powered By LiteSpeed Web Server
LiteSpeed Technologies is not responsible for administration and contents of this web site!

Maybe I need a rewritecond but I don't know what that should be.  

For someone who knows this may be a laughably simple question - but I've spent way to much time trying to figure it out on my own.  A good answer is well worth the 500 points!
0
DMTrump
Asked:
DMTrump
  • 3
  • 2
1 Solution
 
GaryCommented:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?cx=$1 [L]
0
 
DMTrumpAuthor Commented:
Bravo!  Works like a charm...

Now please explain what the two RewriteCond statements do so I'm a little smarter next time

I found that the trouble with most online documentation is it frequently shows stubs rather than complete examples!  Aaargh!
0
 
DMTrumpAuthor Commented:
Thanks a lot!  It's been years since I last messed with htaccess and I seemed to have forgotten everything I knew - which wasn't much!
0
 
GaryCommented:
The two rewrites check the file or directory don't exist so the rewrite rule only fires if they don't
0
 
DMTrumpAuthor Commented:
thanks!  I really appreciate your willingness to help an oldie having a newbee moment!

I'll study more of the htaccess documentation when I'm not in such a blinking hurry!
500 points well spent - okay, I have an unlimited account, so it didn't cost me anything extra - but still - thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now