Jump to content


Photo

mod_rewrite help


  • Please log in to reply
25 replies to this topic

#1 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 28 October 2005 - 11:31 PM

Okay I need to run a normal URL into a full url rewrite. Any suggestions? An example would be:

http://www.netgeekz....ION?48942ed2032
to a url without that PHPSESSION?4803247ekwje (whatever the numbers were)

However it also does it with my dirs like so:
http://www.netgeekz....?849375dkjfew83

Of course my directories all have an index.php file, so that is not displayed if you navigate straight to the dir and no file. So any ideas?

Also can you post why it is done like your example and a great tutorial on learning more about mod_rewrite?

#2 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 30 October 2005 - 12:06 AM

*bump* anyone?

#3 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 31 October 2005 - 07:11 PM

Help would be great!

#4 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 01 November 2005 - 01:08 AM

Anyone?

#5 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 04 November 2005 - 04:23 AM

Hey man, willing to help, but not sure I understand what you want to transform into what. What's the starting data, and what is it you want to have at the end of the rewrite? Can you elaborate a little?
Cook

#6 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 04 November 2005 - 01:07 PM

Well sometimes my session_start(); appeneds that PHPSESSID84890489374 to the end of my urls. I want mod_rewrite to hide that. I don't want them rewrote to anything. Is there a automatic way to do that or do I have to do each one manually?

Also there are urls that are like:

http://www.netgeekz.... Message System

I want to hide that end stuff. Make it go
http://www.netgeekz....ews/archive/30/

Anyway to do that? Also I would like for it to do it automatically because I add news and don't feel like editing anything to expand to the new news articel.

Thanks.

#7 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 04 November 2005 - 01:18 PM

To turn the PHPSESSID rewrite off, you would have to edit your php.ini so that:

session.use_cookies = On
session.use_only_cookies = On
url_rewriter.tags = None

As to your second issue, something like this in your .htaccess should to the trick:

RewriteEngine On
RewriteRule ^/news/view_news\.php http://www.netgeekz.net/news/archive/30/ [R=301,L]

Cook

#8 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 06 November 2005 - 05:04 AM

So is it any good?
Cook

#9 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 06 November 2005 - 06:42 PM

Dosn't work


#10 Guest_footballkid4_*

Guest_footballkid4_*
  • Guests

Posted 06 November 2005 - 09:44 PM

I don't think you could use mod_rewrite to hide PHPSESSID, because how would mod_rewrite know what the SESSID is? It can't just guess it. That has to be changed in your php.ini

Uncomment this line:
; session.use_only_cookies = 1
In php.ini, and set it to 0

#11 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 07 November 2005 - 12:33 AM

Dosn't work

View Post


The PHPSESSID automatic appending to URLs should be turned off with what I gave you for your php.ini. Weird if it's not. It works just fine for me. Do you have control over your php.ini? Is your setup alright? You can try and change the settings at run-time with ini_set() otherwise .

As to the mod_rewrite, this rule is fairly straightforward, am surprised it does not work either. Similarly to the above, do you have control over your .htaccess? Is your setup alright? Is mod_rewrite part of your Apache config (it is an optional module)?
Cook

#12 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 07 November 2005 - 12:40 AM

I don't think you could use mod_rewrite to hide PHPSESSID, because how would mod_rewrite know what the SESSID is?  It can't just guess it.  That has to be changed in your php.ini

Uncomment this line:
; session.use_only_cookies = 1
In php.ini, and set it to 0

View Post


I agree with your php.ini change, as a matter of fact it is what I suggested two posts above.

Now I think it would be possible to remove the PHPSESSID from the URL with mod_rewrite too with a rule looking something like this:

RewriteEngine On
RewriteRule (.*)&PHPSESSID $1

I haven't tried this, but I reckon it should work; However it relies on two assumptions left to be verified: 1- PHP rewrites the URL by appending the PHPSESSID at the very end of the URL; 2- PHP rewrites the URL before Apache does, so that PHPSESSID is in the URL at the time the above rule is run.
Cook

#13 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 07 November 2005 - 02:31 AM

I don't have php.ini setting access. i am on a huge hosting company.

#14 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 07 November 2005 - 02:34 AM

use ini_set at the start of your scripts

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?

ini_set[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"session.use_cookies\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"1\"[/span][span style=\"color:#007700\"]);
[/span][span style=\"color:#0000BB\"]ini_set[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"session.use_only_cookies\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"1\"[/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]?>[/span]
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#15 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 07 November 2005 - 02:58 AM

I don't have php.ini setting access. i am on a huge hosting company.

View Post


What about .htaccess? Does the rewrite rule work?
Cook

#16 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 08 November 2005 - 03:38 AM

No. I also tried Neylital's suggestion, and it was void as well.

#17 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 08 November 2005 - 04:37 AM

I think your next option is to contact your host's technical support...
Cook

#18 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 08 November 2005 - 04:41 AM

No. I also tried Neylital's suggestion, and it was void as well.

View Post

huh. I would have guessed it would work beautifully. Is there a setting in php.ini that says "You can't override this using ini_set"? I've been looking but can't find one... just an idea.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#19 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 11 November 2005 - 02:11 AM

Putting the following in a .htaccess file may help
php_flag session.use_trans_sid off
If you're using php5 you should also be able to use ini_set to change the value.

php4 > 4.23 is supposedly unable to use ini_set to change that particular setting.

ini_list

PHP_INI_ALL in PHP <= 4.2.3. PHP_INI_PERDIR in PHP < 5. Available since PHP 4.0.3.



#20 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 11 November 2005 - 03:00 AM

php4 > 4.23 is supposedly unable to use ini_set to change that particular setting.

PHP_INI_ALL in PHP <= 4.2.3. PHP_INI_PERDIR in PHP < 5. Available since PHP 4.0.3.

View Post

ah... didn't see that bit in there. I must have missed it.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users