|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Hi @all
I've been reading most of the threads on mod_rewrite in this forum specificially the ones with "freebsd" and "forefront". Although I think I understand the basic syntax. I'm not getting any results period. Is there any way to find out if it is working at all? ![]() I compiled Apache with --enable-module=rewrite. Under PHPinfo it says mod_rewrite is installed too. I'm thinking it has to do with me working the whole thing offline (on a linuxbox) or that mod_rewrite is not processing anything. I tried RewriteLog and I don't get any output. Thanks for your help ![]() |
|
#2
|
|||
|
|||
|
What you mean by offline? Apache daemon not running? Or accessing http://localhost or http://192.168.0.1 in your local network or from within your Apache box?
mod_rewrite should work with http://localhost. If you had a problem, please post your code and be more specific, since I have no clue what your problem was. |
|
#3
|
|||
|
|||
|
Hi, freebsd
By offline I meant that I'm not really on a http://www.mysite.com but http://localhost or http://localhost.linuxbox on my laptop. The Apache daemon is running and php works great. Every Code I've tried does not seem to work. My current .htaccess file located in /usr/local/apache/htdocs/ reads: *********************************************************************** RewriteEngine on RewriteRule ^(.+)/$ index.php?id=$1 [T=application/x-httpd-php] *********************************************************************** index.php: <?php echo $id; ?> If I type http://localhost.linuxbox/index.php?id=3 I get "3" on the resulting page. If I type http://localhost.linuxbox/?id=3 I get "3" on the resulting page. If I type http://localhost.linuxbox/3/ I get a 404 error If I type http://localhost.linuxbox/3 I get a 404 error I'm running Mozilla 0.9.2 on Slackware 8.0 with Apache 1.3.19 compiled from sources. I'm thinking it has to do mod_rewrite not being configured right, because I don't get any messages when using : *********************** RewriteLog /home/alex/rewrite.log RewriteLogLevel 9 *********************** and I've tried almost every combination from your posts with forefront. ![]() |
|
#4
|
|||
|
|||
|
Try this(untested):
RewriteEngine on RewriteCond %{REQUEST_URI} ^/index\.php.* RewriteRule ^(.+) - [L] RewriteCond %{REQUEST_URI} ^/(.*)$ RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?id=$1 [T=application/x-httpd-php,L] RewriteRule ^(.+) index.php?id=$1 [T=application/x-httpd-php,L] This intends to work just one level deep, no more no less. http://localhost.linuxbox/3/1/ won't work. Not sure what you trying to do exactly, should people type http://localhost.linuxbox/index.php?id=3 at all? If not, you should consider removing index.php from DirectoryIndex and for a request of ^$, redirect to http://localhost.linuxbox/index/ >> because I don't get any messages when using You also need RewriteEngine on |
|
#5
|
|||
|
|||
|
Nope,
I get the 404 Error: requested URL /3 was not found I tried this with index.php in DirectoryIndex and without it. Same result ![]() Here is what I'm trying to do: 1. Everything from index.php: The only script will be index.php. Using PHP I will search a database based on variables. Ex. http://linuxbox.localhost/Sports/Shoes/Nike/12355453 2. No directories: Only variables after http://linuxbox.localhost 3. No visible script name: The user should never see index.php 4. All links on the web site should also be in the form: http://linuxbox.localhost/ProductGroup/Section/Category Links should adhere to rules 1-3. Basicially the user should never see a URL like: http://linuxbox.localhost/index.php...orts§=Shoes in the locationbar or statusbar. I feel badly because you basically covered all this in your postings with "forefront". And I'm trying to do the same thing. Since I tried all the code from those postings and none of it worked. I was aiming for something really simple in an attempt to get any kind of rewrite result. Thus far I haven't seen the mod_rewrite module do anykind of rewriting I really think my problem has nothing to do with the syntax in the .htaccess file. Just to cover all bases, here is what I do when I change the contents of the .htaccess of httpd.conf files: Restart Apache, clear cache,history in Mozilla I even chmod 777 .htaccess. |
|
#6
|
||||
|
||||
|
I do not know If you already did it,
but instead of putting your rewrite rules inside .htaccess, you could put them inside httpd.conf. If they works OK, then the problem could be that .htaccess is not recognized properly. Just a suggestion. |
|
#7
|
|||
|
|||
|
>> requested URL /3 was not found
Sorry my mistake for not having it tested. The line: RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?id=$1 [T=application/x-httpd-php,L] The 1st / was the problem. >> Here is what I'm trying to do That's what I wanted to know in the first place. 1) Give index.php highest priority for DirectoryIndex 2) Here is a revision (tested): # enabling mod_rewrite RewriteEngine on # for request of http://linux.localhost/ or http://linux.localhost or http://linux.localhost/index.php RewriteCond %{REQUEST_URI} ^/index\.php.* # do not continue and last it RewriteRule ^(.+) - [L] # if request is anything else RewriteCond %{REQUEST_URI} ^/(.*)$ # check and see if the pattern matches # http://linux.localhost/foo -> matches and $QUERY_STRING returns group=foo§ion=category= # http://linux.localhost/foo/bar -> matches and $QUERY_STRING returns group=foo§ion=bar&category= # http://linux.localhost/foo/bar/ha -> matches and $QUERY_STRING returns group=foo§ion=bar&category=ha RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1\§ion=$2\&category=$3 [T=application/x-httpd-php,L] 3) Here is a sample of index.php <html> <body> <?php echo "$QUERY_STRING\n"; ?> </body> </html> As you can see, for /foo, the group would then be foo while section and category get an empty variable. >> you could put them inside httpd.conf That's almost a must for performance and reliability. |
|
#8
|
|||
|
|||
|
Halleluja!!
![]() Finally I get to see the magic of mod_rewrite! ![]() To freebsd, Thanks a millions your code worked great except for: RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1\§ion=$2\&category=$3 [T=application/x-httpd-php,L] Was giving me extra slashes Ex. http://linuxbox.localhost/Produce/Fruits/Apples (//filename:index.php <?php echo $group.$section.$category; ?>) would result in: Produce//Fruits//Apples Remove the slashes from \& to & and you get: ProduceFruitsApples Perfect! Quote:
Yeah, the code above did not work in .htaccess but did work in httpd.conf. Why would .htaccess not be recognized properly? Do I need to edit something in httpd.conf? Bottom Line it works! Thanks again freebsd and pippo |
|
#9
|
|||
|
|||
|
>> Remove the slashes from \& to & and you get: ProduceFruitsApples
If you read the forefront thread again, you would see I didn't escape the & character with a slash for ($1\§ion=$2\&category=$3). Forefront believed the additional slash was OS dependent which I haven't confirmed. It worked on FreeBSD with and without the slash. Just a wild guess, it could be the reason that your mod_php doesn't have --with-system-regex enabled. >> Why would .htaccess not be recognized properly? Start here -> http://httpd.apache.org/docs/mod/mo...l#RewriteEngine Syntax: RewriteEngine on|off Default: RewriteEngine off Context: server config, virtual host, directory, .htaccess Override: FileInfo Status: Extension Module: mod_rewrite.c Compatibility: Apache 1.2 In order for RewriteEngine in .htaccess being parsed by Apache, you need to have AllowOverride FileInfo. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > mod_rewrite offline / on http://localhost? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|