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
https://forums.phpfreaks.com/topic/104260-using-mod_rewrite/#findComment-533769
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
https://forums.phpfreaks.com/topic/104260-using-mod_rewrite/#findComment-533775
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
https://forums.phpfreaks.com/topic/104260-using-mod_rewrite/#findComment-533827
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
https://forums.phpfreaks.com/topic/104260-using-mod_rewrite/#findComment-533830
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
https://forums.phpfreaks.com/topic/104260-using-mod_rewrite/#findComment-533838
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.