Jump to content

mod url rewrite


aebstract

Recommended Posts

Having some trouble, code should be correct.. It's giving me a 404 error when I try to go to:

http://www.berryequipment.net/2/PH/

 

Here is what I have as a .htaccess file in the same directory as my index.php file:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z]+)/$ /index.php?page=$1 [NC,L]
RewriteRule ^([A-Z]+)/([0-9]+)/$ /index.php?page=$1&var1=$2 [NC,L]

 

Will the rewrite only work if I am running it from the root directory? Trying to run this from the folder /2/, it's just a test folder until the site is complete, then it will all get moved to the main directory. If it has to be in the main to work correctly, I'll end up waiting and doing it very last, but please let me know. Thanks!

Link to comment
Share on other sites

The .htaccess file will be in context for the applicable directory

If you want server-wide rewrites why not put them in the httpd conf file?

 

Worth noting...

 

http://httpd.apache.org/docs/2.0/howto/htaccess.html#when

 

In general, you should never use .htaccess files unless you don't have access to the main server configuration file. There is, for example, a prevailing misconception that user authentication should always be done in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things.

 

.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system. In the event that the server administrator is not willing to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where ISPs are hosting multiple user sites on a single machine, and want their users to be able to alter their configuration.

 

However, in general, use of .htaccess files should be avoided when possible. Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration file.

Link to comment
Share on other sites

RewriteEngine On

 

RewriteBase /

 

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([A-Z]+)/$ /index.php?page=$1 [NC,L]

RewriteRule ^([A-Z]+)/([0-9]+)/$ /index.php?page=$1&var1=$2 [NC,L]

 

greetings, the rewrite rules above would need the following urls to work

 

/bob/

/bob/4/

it appears you want it the other way around ie

/2/

/2/bob/

 

RewriteRule ^([0-9]+)/$ /index.php?page=$1 [NC,L]
RewriteRule ^([0-9]+)/([A-Z]+)/$ /index.php?page=$1&var1=$2 [NC,L]

That should give you want you requested above

 

Please note, the NC means no Case, so it should match BOB bob BoB Bob bOB etc etc

 

These rules can be put in your root .htaccess folder, If you want to put them in the folder 2

 

RewriteBase /2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z]+)/$ /index.php?page=$1 [NC,L]

 

that should do it.

 

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.