FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Apache mod_rewrite questions.





likeabreeze
Environment: Apache+PHP

1. Type
Code:
www.abc.com/index.php?page=13
, and it's automatically redirected to
Code:
www.abc.com/13.page

2. Type
Code:
www.abc.com/view.php?t=i-am-here
, and it's automatically redirected to
Code:
www.abc.com/i-am-here/

3. Type
Code:
www.abc.com/i-am-here
,and it's automatically redirected to
Code:
www.abc.com/i-am-here/


I just don't know how to do these three tasks. I have to use mod_rewrite, right?
BTW, I took a look at WordPress .htaccess, only to found
Code:
Options All -Indexes
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Well, I really don't know how WordPress do the three tasks above..
In other words, what's the mechanics behind WordPress permalinks mode?
jmraker
Quote:
I just don't know how to do these three tasks. I have to use mod_rewrite, right?
BTW, I took a look at WordPress .htaccess, only to found
Code:
Options All -Indexes
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Well, I really don't know how WordPress do the three tasks above..
In other words, what's the mechanics behind WordPress permalinks mode?


The configuration above does need mod_rewrite

RewriteCond %{REQUEST_FILENAME} !-f
Means "If the requested page doesn't exist as a file"

RewriteCond %{REQUEST_FILENAME} !-d
Means "If the requested page doesn't exist as a directory"

If both of those conditions are true then it rewrites the URL to index.php and that program can either show an error message or grab and parse the original URL string and return it's database content based on it.

The /index.php would handle any invalid request, and usually treat it as it was valid.

I used the rewrite rule generator at http://www.generateit.net/mod-rewrite/
to create
Code:
RewriteEngine On
RewriteRule ^([^/]*)\.page$ /index.php?page=$1 [L]

that should rewrite http://www.abc.com/13.page to http://www.abc.com/index.php?page=13
The others shouldn't be that hard. I entered the http://www.abc.com/index.php?page=13 url and on the 2nd page I changed the Parameters, Prefix, Delimiters, and/or Suffix until it showed the re-written rule you had.

http://www.modrewrite.com/
http://httpd.apache.org/docs/2.4/rewrite/remapping.html
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
likeabreeze
Thanks for your explanation.
I did a research, and found out /wp-inculdes/rewrite.php is related to this issue, but that's so complicated.
metalfreek
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1


here is my .htaccess which turns URL like profile.php?user=metalfreek to mysite.com/metalfreek

Hope it helps.
Related topics
mod_rewrite in Apache and how does it work?
.htaccess instead of mod_rewrite
only .htaccess instead of mod_rewrite
Proactively connecting Apache to the browser
problema con el mod_rewrite en wmserver 3.3
75FRIH$ Mod_Rewrite Code
URL Cloaking / mod_rewrite advice needed
Two questions.
Apache mod_rewrite
how to make old html point to php
Some frihost questions (do you have apache ect ect)
Google Indexing .Com and .Com/index.php --> Redirect
* * * * Apache problems in WAMP 2 server * * * *
hide folder or files in url bar
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.