Jump to content

mod_rewrite help


steelmanronald06

Recommended Posts

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

 

http://www.netgeekz.net/PHPSESSION?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.net/directory/PHPSESSION?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?

Link to comment
Share on other sites

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.net/news/view_news.php...+Message+System

 

I want to hide that end stuff. Make it go

http://www.netgeekz.net/news/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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

Guest footballkid4

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

Link to comment
Share on other sites

Dosn't work

315463[/snapback]

 

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)?

Link to comment
Share on other sites

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

315535[/snapback]

 

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.

Link to comment
Share on other sites

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--]

Link to comment
Share on other sites

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

316066[/snapback]

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Talking to my host about the PHPSESSID. As to my other question...it didn't work. What I want is for the url:

 

http://www.netgeekz.net/news.php?article=1

 

To be changed to

 

http://www.netgeekz.net/news/1/

 

However I don't want to do that manually myself with each news post. I want every url to automatically be done. And example:

 

http://www.netgeekz.net/news.php?article=1 Changes to http://www.netgeekz.net/news/1/ Automatically

 

http://www.netgeekz.net/news.php?article=2 Changes to

http://www.netgeekz.net/news/2/ Automatically

 

And so on and so forth.

Link to comment
Share on other sites

As to my other question...it didn't work.

What are you referring to?

 

http://www.netgeekz.net/news.php?article=1

 

To be changed to

 

http://www.netgeekz.net/news/1/

 

However I don't want to do that manually myself with each news post. I want every url to automatically be done. And example:

 

http://www.netgeekz.net/news.php?article=1 Changes to http://www.netgeekz.net/news/1/  Automatically

ModRewrite manipulates the request sent by the client. What you seem to be asking to do, is to manipulate your script's output similar to what PHP does when it adds the "session id" to the end of links etc.

 

Unless you modify PHP or Apache itself, I don't know of a way to accomplish that. To be clear however, I'm assuming that when you say you don't want to do it manually. You mean you don't want to go through your scripts, modifying the places where you output links(<a href="">)

 

EDIT: Actually I forgot about the output control functions that would allow you to modify the script's output

Link to comment
Share on other sites

http://www.netgeekz.net/news.php?article=1 Changes to http://www.netgeekz.net/news/1/  Automatically

 

http://www.netgeekz.net/news.php?article=2 Changes to

http://www.netgeekz.net/news/2/ Automatically

 

And so on and so forth.

317319[/snapback]

 

I've reworked my suggestion now that I understand better what you need. But again you'll have to have your host put this into an .htaccess for you if they don't allow you to do it yourself.

 

RewriteEngine On
RewriteRule ^/news\.php\?article=(.*) http://www.netgeekz.net/news/$1/ [R=301,L]

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.