Jump to content

mod_rewrite Issue


PTS

Recommended Posts

Was hoping someone might be able to help me with a rewrite issue I'm having.

 

I would like for my clients to control the URL of any page they create in our custom CMS.

 

Let's say my client creates three pages in our CMS and enters the following values for the FURL field:

 

1. "services/design.php"

2. "products/software/1/"

3. "news"

 

I would like for the following URLs to work based on those FURL field entries:

 

1. http://www.domain.com/services/design.php

2. http://www.domain.com/products/software/1/

3. http://www.domain.com/news

 

Basically, I'd like for them to control whatever the URL is after "http://www.domain.com/". Is this possible? I've tried various methods and all have failed.

 

The dynamic link is: http://www.domain.com/content.php?furl=page-link-here

 

Hope someone might be able to help me out. Thanks!

Link to comment
Share on other sites

1. Store everything in a database (duh).

2. Use mod_rewrite to redirect any non-existant URLs to some PHP script (your content.php I would guess).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*) content.php?furl=$1 [L]

3. Have the script display the content associated with the URL, or show an error if there isn't anything.

Link to comment
Share on other sites

THANK YOU! You are a life saver.

 

I was messing around with the RewriteRule seven ways to Sunday. I never knew you needed these two lines for it to work:

 

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

 

I tested out a variety of inputs and all the ones that failed before are working correctly now.

Link to comment
Share on other sites

I never knew you needed these two lines for it to work:

 

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

Without them, mod_rewrite will apply (successfully, because the regex is so broad) that Rule to every request that comes in. Everything will go to content.php: requests to existing PHP scripts, CSS and JavaScript files, images...

With them, only requests that don't exist (legitimate 404s or otherwise) will make it to the Rule.

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.