Jump to content

[SOLVED] Need help with mod rewrite


rondog

Recommended Posts

In an effort to make a site I am working on more search engine friendly I need to manipulate the URLs a bit. Say I have a link that looks like this:

http://mysite.com/?page=optimization

 

I would like to use mod rewrite to make it something like this: http://mysite.com/solutions/optimization

 

How would I write that? I've googled but regular expression is beyond me at this point. Any help would be appreciated. Thanks.

Link to comment
Share on other sites

RewriteRule ^([^/])/?$ /?page=$1

 

 

Will redirect blah to ?page=blah.

 

 

You could throw solutions in there if you want:

 

RewriteRule ^solutions/([^/])/?$ /?page=$1

 

I'm not really following..What exactly is ^([^/])/?$ doing?

Link to comment
Share on other sites

Just noticed that

 

^([^/])/?$

 

Should be

 

^([^/]+)/?$

 

 

I can explain it in detail if you want, but it essentially forwards:

 

somesites.com/blah/ to somesite.com/?page=blah

 

Where blah is a string composed of anything but /.

Link to comment
Share on other sites

Mod rewrite has nothing to do with HTML content or PHP pages.

 

It simply internally (or sometimes externally) 'translates' the incoming URI to the correct thing for Apache to do.

 

 

 

Simple answer: You have to change links your self, or just do it with a script.

Link to comment
Share on other sites

  • 1 month later...

I am trying to get this to work yet again and am having problems

 

I have a link like this:

http://mysite.com/?page=news&id=25

 

I want it displayed as

 

http://mysite.com/news/25

 

My .htaccess file contains this. I cant get it working :(

LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^news/([0-9]+)$ ?page=news&id=$1

Link to comment
Share on other sites

ok I managed to get it working..for some reason my styles are not loading correctly however.

 

Visit http://ostari.com, on the left click one of the news links that say "See More"

 

Notice all my styles go away..what do I need to do to ensure this doesnt happen?

 

here is my .htaccess file as of now:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^news/([0-9]+)$ ?page=news&id=$1

 

Firebug is telling me my css file cant be found and its looking in /news/inc/css/main.css

 

when really it is just /inc/css/main.css

 

Is their a RewriteRule I can do for that?

Link to comment
Share on other sites

if I do this:

RewriteRule /inc/css/main.css http://ostari.com/inc/css/main.css

 

it kinda works..ehh there has to be a better way..

 

I also tried:

RewriteRule /inc/css/main.css ../inc/css/main.css

 

which gave me a 404 not found and then tried:

RewriteRule /inc/css/main.css ^../inc/css/main.css

 

which gave me a 500 internal server error.

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.