Jump to content
Sign in to follow this  
Skitty

PHP and mod rewrite

Recommended Posts

Skitty

I've been working on this php script based off of tinyib to work just like 4chan, yeah.. you heard right.

I came to a problem when I noticed how 4chan interprets page requests as so~

<a href="1">1</a>

Now the above is obviously a request for the second page on almost any board at the place and when you click it, the url changes from ~

http://boards.4chan.org/g/

to the url

http://boards.4chan.org/g/1

And if you add a trailing backslash to the url as so~

http://boards.4chan.org/g/1/

you will get an error which should mean the request is not a directory but an argument sent over the url like the typical forum values you see like ~

forum.net/forum.php?Page=1

Some one told me that moot uses mod_rewrite to interpret the request, I couldn't get the said module to work under uniserver for some reason, even though "server-info" screams at me that the module is loaded and ready to go, but when I add a rule, it gives me a server error or apache fails to run when restarted.

I'm basically very close to replicating 4chans script. but I cannot figure out how to interpret the url in my script so I can deliver the right page.

Heres how 4chan uses the page ref ~

<a href="1">1</a>

Very simple looking but I don't know how to catch this and not get a 404 error because of the "1" which apache thinks is a directory.

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Valik

Did you turn the rewrite engine on? It's not very helpful when you don't show how you are using mod_rewrite nor is it helpful when you don't give an exact error.

Share this post


Link to post
Share on other sites
Skitty

Loaded items

Loadfile "C:/UniServer/usr/local/php/ssleay32.dll"
Loadfile "C:/UniServer/usr/local/php/libeay32.dll"
Loadfile "C:/UniServer/usr/local/php/libmysql.dll"
#Loadfile "C:/UniServer/usr/local/php/php5ts.dll"
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_alias_module modules/mod_authn_alias.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cache_module modules/mod_cache.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule charset_lite_module modules/mod_charset_lite.so
LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule dav_lock_module modules/mod_dav_lock.so
#LoadModule dbd_module modules/mod_dbd.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
#LoadModule disk_cache_module modules/mod_disk_cache.so
#LoadModule dumpio_module modules/mod_dumpio.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
#LoadModule ident_module modules/mod_ident.so
#LoadModule imagemap_module modules/mod_imagemap.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
#LoadModule ldap_module modules/mod_ldap.so
#LoadModule logio_module modules/mod_logio.so
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_forensic_module modules/mod_log_forensic.so
#LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
#LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
LoadModule version_module modules/mod_version.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so

Virtual Host

<VirtualHost *:80 >
RewriteEngine On
RewriteOptions Inherit
  ServerName boards.phpchan.tk
  DocumentRoot C:/UniServer/www/chan
</VirtualHost>

Testing rewrite conditions I've used and do not work in neither .htaccess or httpd.conf

DirectoryIndex index.html
addtype application/x-httpd-php .php .html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

the errors I get are usually 404's and 401's, I believe I was getting a 404 due to a bad alias condition I had in httpd.conf, as for the 401's, I do not have anything blocked so I can't see why I was getting that.

On a side note, I even tested this with

RewriteBase   /test
RewriteRule   ^index\.html$  1

just to see if it was working, obviously nothing is working with mod rewrites or I am failing to understand how to do this properly, I've already almost religiously followed every tutorial I've encountered on the web and still can't get this right.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Valik

This was placed inside a VirtualHost section:

RewriteEngine On
RewriteRule ^/index\.shtml /test2.html
RewriteRule ^/$ /test2.html

It replaced both http://domain/ and http://domain/index.shtml with http://domain/test2.html. I imagine what you need is:

RewriteEngine On
RewriteRule ^/g/$ /g/1

Share this post


Link to post
Share on other sites
Skitty

Thanks, I noticed the message was actually saying there was an internal error, the error info I gave earlier was incorrect, at the last minute, I actually noticed what was going on.

lol, silly me.

So I checked in the apache error log and found this nifty message that was logged more than a few thousand times and started getting logged around the same time I started trying this (yesterday), the massage ~

[error] [client 70.124.221.65] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: C:/UniServer/www/test.php

So I threw this into .htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^b$ test.php [L]
</IfModule>

And viola, moral of story; if there are error log files, f***ing use them.

Thank you for the assistance Valik.

Edit: But the main point of this thread remains unsolved, how do I catch the "1" value in the php script when its requested in this manner?

Subsequent Edit: Never mined, I've think I got this.

"modrewrite"

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase   /
RewriteRule ^test/(.*)$ test.php
</IfModule>

Example php usage

<?php
$T=explode('/',$_SERVER["REQUEST_URI"],3);
$X=$T{2};
$Y = $X + 1;
echo'<a href="'.$Y.'">'.$Y.'</a>'
?>

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
Skitty

Subsequent Edit: Never mined, I've think I got this.

"modrewrite"

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase   /
RewriteRule ^test/(.*)$ test.php
</IfModule>

Example php usage

<?php
$T=explode('/',$_SERVER["REQUEST_URI"],3);
$X=$T{2};
$Y = $X + 1;
echo'<a href="'.$Y.'">'.$Y.'</a>'
?>

the above was a crude way of doing it.

The below is what I needed.

RewriteRule ^([a-zA-Z0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9])/([0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9])/([0-1][0-5])/?$ test.php?board=$1&page=$2
 
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9])/([0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9])/([0-1][0-5])/?$ test.php?board=$1&page=$2
 
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/([0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/([0-1][0-5])/?$ test.php?board=$1&page=$2
 
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/([0-9])/?$ test.php?board=$1&page=$2
RewriteRule ^([a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9])/([0-1][0-5])/?$ test.php?board=$1&page=$2

<html>
   <head>
      <title>mod_rewrite test</title>
   </head>
   <body>
      <p>
         The requested board is:
         <?php echo $_GET['board']; ?>
      </p>
<p>
         The requested page is:
         <?php echo $_GET['page']; ?>
</p>
<?php $X=$_GET['page'];$Y = $X + 1;echo'<a href="'.$Y.'">'.$Y.'</a>' ?>
   </body>
</html>

Although, I am still having a problem figuring out a legitimate easy way to fix up the url in the users browser, lets say we were at "thisdomain.com" and we requested board "x", the url will look like "thisdomain.com/x".

How can I have the url be set as "thisdomain.com/x/", with the appended forward slash?

If you go to "boards.4chan.org/g" the url is set as "boards.4chan.org/g/", automatically appending the forward slash, the guy running that place sure used a whole boat load of mod rewrite tricks or something.

How would I go about adding that forward slash if its missing? I.e If you use the above example php and mod rewrite code and access the script w/o appending the slash mark and you click on the number link, the number is appended to the letter of the board requested, how do I stop that?

Edit: More specifically, I'm currently attempting to figure out how to append the trailing slash to the requested board, and if a board is requested along with the page number like so "domain.com/x/1/", give a 404, which shouldn't be to hard.

Edit #2: Obviously, I don't think mod rewrite is what I'm looking for in order to append the trailing slash on the client side, I guess I'll have to jumble up some php that echo's a meta refresh tag that fixes the url.

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
shanet

I've been working on this php script based off of tinybb to work just like 4chan, yeah.. you heard right.

I came to a problem when I noticed how 4chan interprets page requests as so~

<a href="1">1</a>

Now the above is obviously a request for the second page on almost any board at the place and when you click it, the url changes from ~

http://boards.4chan.org/g/

to the url

http://boards.4chan.org/g/1

And if you add a trailing backslash to the url as so~

http://boards.4chan.org/g/1/

you will get an error which should mean the request is not a directory but an argument sent over the url like the typical forum values you see like ~

forum.net/forum.php?Page=1

Some one told me that moot uses mod_rewrite to interpret the request, I couldn't get the said module to work under uniserver for some reason, even though "server-info" screams at me that the module is loaded and ready to go, but when I add a rule, it gives me a server error or apache fails to run when restarted.

I'm basically very close to replicating 4chans script. but I cannot figure out how to interpret the url in my script so I can deliver the right page.

Heres how 4chan uses the page ref ~

<a href="1">1</a>

Very simple looking but I don't know how to catch this and not get a 404 error because of the "1" which apache thinks is a directory.

What you need to do is the following:

<IfModule mod_rewrite.c>
#Turn on the engine
RewriteEngine on
#Set the base
RewriteBase (Set your base here)
 
RewriteRule ^\/g\/([0-9]+)\/?$ forum\.php?Page=$1 [L]
#First group is searching for what page the user is on
#Second group is where this request will be directed to on the directory
#[L] stops any more rules from executing
</IfModule>

Hope this helps!

Shane

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites
Skitty

Hope this helps!

Shane

Sure did, thanks.

I can't believe I overlooked the [L] parameter, it was something I needed.

I also need to mention that It was my mistake saying this is based off of tinybb, when really it was tinyib...


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites
ProgAndy

By the way, the parameter QSA is also useful. This allows to use GET-parameters in the URL, too. Example:

example.com/g/1?order=y

without QSA: example.com/forum.php?Page=1

with QSA: example.com/forum.php?order=y&Page=1

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
shanet

Oh yes I completely overlooked QSA ;)

Thanks ProgAndy :)

For the OP, QSA stands for Query String Append.

The flag could/should be changed to [QSA,L]

Glad to hear that it helped :graduated:


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • 31290
      By 31290
      Hi everyone, hope you are doing fine
      Well, I'm currently writing a small script that goes to a certain web page, finds the first link of a specified section and download the file associated to this link.
      Depending on the computer that the tool is launched, the script gets the computer model and search in the (provided here) ini file which link to follow.
      At first, Dell was kind enough to provide only one link but now, they provide two of them. The first one is now a .txt file (  ) whereas my script has been designed to download only the fist and latest link released for the BIOS Update.

      Here's the current code which is working with only the first and latest link of the BIOS category:
      So the question is: 
      In the case of double links like shown in the picture above, how it is possible to tell the script to download only the link containing an the .exe file?
      Of course, I could have changed the array result to [1] instead of [0] [which is working] but it seems that Dell does that randomly and that I deal with a lot of computer models.
      Thanks for the help you can provide, 
      -31290-
       
      SEE_BIOS_LINKS.ini
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • zenocon
      By zenocon
      Hi, After scouring the forums for many hours, I'm trying to compile the most up to date / recent information on the options available for integrating with JavaScript / DOM -- as it relates to scraping + automation of web pages.
      It's my understanding there is IE.au3 script for automation of IE through a COM interface.  But I believe this only works with IE and won't work with Edge, correct?  Is there a COM interface that works with Edge, or any other options for integrating with Edge (other than IUIAuatomation?)
      I know there was also a FF.au3 UDF, but Mozilla abandoned the support for their mozrepl in favor of Web Extensions, and my understanding is that the FF.au3 UDF no longer works, is that correct?
      There was also a Chrome.au3 UDF, but my read on the forums indicate that this also broke many Chrome releases past.
      Which leaves IUIAutomation which I have been using to automate / scrape Windows apps, but when I am trying it on a website, it is not as useful.  For example, if I know the exact DOM id / class, I can get at it and do whatever I need to in JavaScript very simply.  With IUIAutomation, the DOM properties are not available, and most tags / elements in DOM have no useful defining characteristics to be able to get at them reliably (if they are targetable at all).  Some things might be able to be done with IUIAutomation, but I see it's value in targeting website automation / scraping as fairly limited.
      At this point, it seems like my best option is to use IE.au3, but that forces users on IE, which is probably a showstopper.
      Is there another way to bridge into the DOM?  I have written Web Extensions for Chrome and Firefox before.  They can communicate with external processes via AJAX or messaging.  I'm wondering if I can build what I need in a WebExtension and then trigger it from AutoIT Script, and gather up the results somewhere.
      I know there was the ISimpleDOM.au3 and some Microsoft Accessability scripts, but they seem to only be partially supported in browsers, and I didn't have a lot of luck getting those examples to run correctly.
    • Jefrey
      By Jefrey
      I've made this HTTP lib to simplify HTTP requests, mainly when dealing about POST data or file uploads.
      Three functions are available:
      string _HTTP_Get ( string $sURL ) string _HTTP_Post ( string $sURL , string $sPostData ) string _HTTP_Upload ( string $sURL , string $sFilePath , string $sFileField , string $sPostData = '' , string $sFilename = Default) Additionaly, two helper functions are also available:
      URLEncode($sStr) URLDecode($sStr) Full documentation: https://github.com/jesobreira/HTTP.au3/blob/master/README.md
      Fork me on Github: https://github.com/jesobreira/HTTP.au3
      Download lib + docs: https://github.com/jesobreira/HTTP.au3/archive/master.zip
    • seppedelanghe
      By seppedelanghe
      Hi everyone,
      First of all sorry for my bad english.
      I'm trying to build a automated program/autoit that controls a web app.
      I created the script using mouseclick() , but i don't want the web browser to be visible.
      I tried ControlClick() , but the web app uses flash and the buttons/items to be clicked do not have an ID.
      I searched and visited a lott of autoit post and pages (even in german  ) , but could not find a way or get it to work.
      Any help is welcome!!!
      Thanks already
      Seppe
×