PDA

View Full Version : Mod Rewrite not working for newbie



csreso
07-02-2007, 12:20 PM
Hi all,

Here is my site, that I want this mod to work on.

Here is the .htaccess contents.

Options +FollowSymLinks
RewriteEngine on
RewriteRule Resources(.*)-(.*)\.htm$ /resource.php?resourceid=$1&titleid=$2 [L]
RewriteRule articles(.*)-(.*)\.htm$ /article.php?articleid=$1&titleid=$2 [L]
RewriteRule homepage/(.*)/(.*)/$ /homepage.php?$1=$2
RewriteRule results(.*)\.htm$ /results.php?category=$1 [L]
RewriteRule info(.*)\.htm$ /info.php?jobid=$1 [L]

These are the links I want to work with they have all my contents:

http://www.charityemployers.com/homepage.php?companyname=canadian-cancer-society

http://www.charityemployers.com/info.php?jobid=20

http://www.charityemployers.com/results.php?category=call_centre/telemarketing

http://www.charityemployers.com/article.php?articleid=7&titleid=1

http://www.charityemployers.com/resource.php?resourceid=3&titleid=1

I tried posting a test, but it's still giving the /info.php? etc.
Does that mean it's not working right, it should have html at the end.
Am I missing something?

HELP!

Plus there after I would like to convert the existing to friendly URL as well.
This site uses CMS.

Please help, I am really trying.

Regards
Lennox

Basil
07-03-2007, 11:16 AM
RewriteEngine on
RewriteBase /
RewriteRule ^Resources(.*)-(.*)\.htm$ http://charityemployers.com/resource.php?resourceid=$1&titleid=$2
RewriteRule ^articles(.*)-(.*)\.htm$ http://charityemployers.com/article.php?articleid=$1&titleid=$2
RewriteRule ^homepage/(.*)/(.*)/$ http://charityemployers.com/homepage.php?$1=$2
RewriteRule ^results(.*)\.htm$ http://charityemployers.com/results.php?category=$1
RewriteRule ^info(.*)\.htm$ http://charityemployers.com/info.php?jobid=$1

csreso
07-04-2007, 07:56 AM
Thanks for your answering my cry for help.
I copied the code into my .htaccess, my website would not display after I copied and saved. I got the following error:

(Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@charityemployers.discoverme.ca and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request)

What does it mean?
How can I fix this?

Thanks

jiml8
07-04-2007, 09:37 AM
Start your test string with a carat, like this for instance:
RewriteRule ^Resources(.*)-(.*)\.htm$ /resource.php?resourceid=$1&titleid=$2 [L]

Also understand that only incoming URLs will be rewritten. You need to write your own outgoing URLs in the format you desire, then expect mod_rewrite to rewrite them when someone clicks on them.

csreso
07-04-2007, 02:27 PM
Hi jiml8

I tried what you stated, I am NOT getting the error message anymore and my site did not disappear. I post a job to perform a test to see if it work, but my URL is still showing up as ?php etc.
No friendly URL.

So to view the tested job, I am still seeing the same ?php as the other posted jobs before mod_rewrite.

Any other suggestions?

Thanks

jiml8
07-04-2007, 02:53 PM
I repeat:

"Also understand that only incoming URLs will be rewritten. You need to write your own outgoing URLs in the format you desire, then expect mod_rewrite to rewrite them when someone clicks on them."

csreso
07-04-2007, 08:07 PM
Let me see if I understand this, so only incoming from the search engines will pickup the friendly URLs. So when they come to the site, and click on a link, it will still how the id=?.php etc.

I thougt it's supposed to show the friendly URL so visitors will remember them, thats the hold idea.
And if a search engine comes to my site, it's going to see the samething I am seeing, which is id?php etc.

What I have read, they are saying you should see format such as: /site/index.htm etc.

Remember, I post a new job after I configure .htaccess. This was supposed to create the new link,which it did not, still remains that funny looking link.

I hope this is explained ok...

Basil
07-04-2007, 10:26 PM
I have no problem with the code I posted.

See for yourself: http://semlar.biz/test/

Pethens
07-05-2007, 08:18 AM
Just to expand on what was said already about friendly URLs: the mod_rewrite rules you have are just there to make sure that your site still works when someone uses a friendly URL. When they use the URL

http://mysite.com/pages/friendlypage

they will be taken (silently) to

http://mysite.com/index.php?page=friendlypage

(just an example). The second URL is the one your site is designed to work with. Once you have installed these rules, you still have to do the second part of the job, which is to start using the friendly URLs everywhere you link to your own pages.

It's possible to add a second set of rules which 301 redirects from the old dynamic URLs to the new friendly URLs, but this requires advanced skills and it's usually not done.

csreso
07-05-2007, 08:21 AM
Hey there

Clicking on your test link gives me the same error as what I am receiving on my site.

All I did was copy what you gave me into my .htaccess, go to my www.charityemployers.com, and the site gives
me the error. So I had remove the script and then the site is back.

Regards
Lennox
:rolleyes: :eek:

csreso
07-05-2007, 08:28 AM
Pethens

Oh I see, so even through I put the .htaccess, I will still have to go in and change my links.

1. So if I have a link going to www.mysite.com/job/homepage.php?=id etc.

2. I would need to change the above link to the friendly URL,( what ever it is) and the friendly URL will take me to above link (DB).

3. But of course I have to set these up in the .htaccess.

Regards

csreso
07-05-2007, 08:48 AM
Pethens

Sorry, I am sooo new at this MOD thing,
So I need to replace my existing links that leads to a DB link?

Example:
Current Link:http://charityemployers.com/resource.php?resourceid=$1&titleid=$2

New link will be:Resources(.*)-(.*)\.htm$

But of course these URL MUST be in the .htaccess

You can all my links above from for my site, that someone helped me with.

Regards

Pethens
07-05-2007, 09:13 AM
Oh I see, so even through I put the .htaccess, I will still have to go in and change my links.

1. So if I have a link going to www.mysite.com/job/homepage.php?=id etc.

2. I would need to change the above link to the friendly URL,( what ever it is) and the friendly URL will take me to above link (DB).


Exactly. The old dynamic link will still work also, but you just don't use it anymore.

Basil
07-05-2007, 11:04 AM
Hey there

Clicking on your test link gives me the same error as what I am receiving on my site.

All I did was copy what you gave me into my .htaccess, go to my www.charityemployers.com, and the site gives
me the error. So I had remove the script and then the site is back.

Regards
Lennox
:rolleyes: :eek:
You get a 500 error on my page?

csreso
07-05-2007, 08:45 PM
I am fustrated now, this thing is NOT working for me. I am about to put throw this computer off the desk.

GRRRRRR....

I have the script in my .htaccess

This is one of my existing link:

http://www.charityemployers.com/homepage.php?companyname=action-against-hunger

This is my script:

RewriteRule homepage/(.*)/(.*)/$ /homepage.php?$1=$2

This is what I place in my URL from above:

/homepage/(.*)/(.*)/$

This is what my URL looks like before I enter the above:

<a href='<?=$fullurl?>/homepage.php?companyname=<?=$string?>

This is what I enter: /homepage/(.*)/(.*)/$/companyname=<?=$string?>
*** I have tried several ways of strings, but nothing I get a 404 error, blank page****

Ohh boy boy, not sure what I am doing wrong. I have a few more links to setup.

HeLP!!

Pethens
07-05-2007, 09:12 PM
Actually, given the rewrite rule you are using, this is the friendly URL you should use for linking to the page:

http://www.charityemployers.com/homepage/companyname/action-against-hunger/

...and it seems to work fine. Is there something else you are trying to accomplish?

csreso
07-06-2007, 06:22 AM
Yes, there are things I am trying to accomplished. But I am soooo confused.
This what I want to do, I have a job site, jobs are already been posted and want the existing jobs to be URL friendly as well as the new jobs that will be posted.

http://www.charityemployers.com/home...against-hunger
The above link is a company that posted a position, I cannot change each link that lead to a company. So I would change the main URL that points to the pages with these jobs.

If you go to the site you will see the logo's on the left, I want the search engine to pick up the links from there.

Plus I have some articles etc. I want the search engines to pickup also.

The links are on the top of thread (first post )

jbladeus
07-08-2007, 06:06 AM
I've found the following an excellent mod-rewrite tool for newbies:
http://www.mod-rewrite-wizard.com/

Basil
07-09-2007, 08:39 AM
I must just not understand what you're trying to accomplish here.

If you just want to change the menu links what is stopping you?

adrivers
05-12-2008, 02:34 PM
Did anybody find solution for this issue. I use the same code change the site variable but I am still getting url variables showing.

adrivers
05-12-2008, 04:45 PM
My website my domain is an add-on hosted on bluehost.

Here is my url: http://adrivers.com/viewTrucks.php?sID=18%20&%20sName=Louisiana

I want change it to http://adrivers.com/viewTrucks.php/Lousiana/18.html

I tried many examples and could not get it working. My .htaccess file is located on the root folder instead of the domain add-on folder.

Any help??

Here is the last example I tried:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^sName\=([^&]+)\&sID\=([^&]+)$
RewriteRule ^$ /viewTrucks/%1-%2.html [R=301,L]

JoshFinnie
07-17-2008, 08:20 AM
My website my domain is an add-on hosted on bluehost.

Here is my url: http://adrivers.com/viewTrucks.php?sID=18%20&%20sName=Louisiana

I want change it to http://adrivers.com/viewTrucks.php/Lousiana/18.html

I tried many examples and could not get it working. My .htaccess file is located on the root folder instead of the domain add-on folder.

Any help??

Here is the last example I tried:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^sName\=([^&]+)\&sID\=([^&]+)$
RewriteRule ^$ /viewTrucks/%1-%2.html [R=301,L]

Try this one?


RewriteEngine On
RewriteRule ^viewTrucks\.php/([^/]*)/([^/]*)\.html$ /viewTrucks.php?sID=$2&Name=$1

csreso
06-23-2009, 02:25 PM
Hello,

I just want to say thanks for everyone that helped me on my mod rewrite. I am now using it on my site. http://www.discoverme.ca
The first site was at http://www.charityemployers.com, and this was my first site, and believe you it was tuff at first but now I am got the hang of things.

Thanks to bluehost and and all the members for their help.

Regards
Lennox