Jump to content

Using mod_rewrite


Recommended Posts

I need to take a URL such as:

 

http://www.somesite.come/RANDOM_TEXT

 

and turn it into:

 

http://www.somesite.com/site?siteName=RANDOM_TEXT

 

Could someone show me how to do that?

 

I want to give the appearance of individual directories without all the hassle as one "Super Mod" pointed out to me.

 

(Thanks by the way)

 

 

Thanks!

 

--Elite

 

Link to comment
Share on other sites

The example you gave would be:

 

<IfModule mod_rewrite.c>

RewriteEngine On

</IfModule>

RewriteRule ^([a-zA-Z0-9]+)$ site?siteName=$1

RewriteRule ^([a-zA-Z0-9]+)/$ site?siteName=$1

 

That'll take any alphanumeric value request in the directory that you put this .htaccess in (no underscores, but I could add it....) and send it to site?siteName="whatever".

Link to comment
Share on other sites

Okay, when I click "Create New Directory" I enter .htaccess then I added

 

<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
RewriteRule ^([a-zA-Z0-9_]+)$ site?siteName=$1
RewriteRule ^([a-zA-Z0-9_]+)/$ site?siteName=$1

 

Then I click "Save File" and the file never appears. But when I name it something like htaccess.htaccess the file appears. But I keep getting a page not found error.

 

The .htaccess file is in my root directory in public HTML. So when I type an address like this: http://www.somesite.com/fun the Super Global $_get[] should recieve the siteName variable and recieve the value "fun" but I have a index.php file set up in the /site/ directory with

 

<?php

echo $_GET['site'];

?>

 

But I never get to the index.php, just a cheap error page.

Link to comment
Share on other sites

It's NOT a directory, it's a file.  And it'll appear hidden if you use Linux because . in front of a filename means "hidden", but Apache REQUIRES it to be named .htaccess.  Now.  Just add a file ".htaccess" with that in it, and make sure you put the right page in....if it's index.php, use that....>_>

Link to comment
Share on other sites

The mod_rewrite should be able to handle several pages at once.

 

Like I said, I want it to appear that they are in a separate directory. So users should be able to navigate through links and stuff without them ever seeing anything but their subdirectory.

 

Link to comment
Share on other sites

You're going to need a hell of a lot of rewrite rules for that, unless you made a master page which took the GET from the mod_rewrite and included the page (your best bet, probably, but make sure it doesn't include anything sensitive).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.