Page 1 of 1
Url rewriting problem
Posted: Mon Dec 29, 2008 11:23 pm
by kalpesh
hi, i am to php. i want to write rewrite url for the following url
First my url like this:
http://www.example.com/City/index.php?City=New York
After Url rewriting i want it like this
After select it has like this :
http://www.example.com/New York/index.php
I know that url rewrting rule written in .htaccess
but where to store that .htaccess so it can be apply to whole site.
If i store .htaccess in
http://www.example.com/include/ folder then it can also rewrite url or i have to place in root folder.
Please Help me.
Thanks in advance.
Re: Url rewriting problem
Posted: Mon Dec 29, 2008 11:36 pm
by requinix
If you're rewriting /
city into /City/index.php the only thing the two have in common is the root. That's where the .htaccess goes.
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)(/index.php)? /City/index.php?City=$1 [QSA]
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 12:58 am
by kalpesh
I do not get what r u trying to say?
Can i dont get what i want?
Please properly explain to me.
thanks for Replying.
I really appreciate that.
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 1:19 am
by requinix
"Properly"? Besides your not understanding, was there something wrong with it?
My opinion is that .htaccess files should be placed in the "greatest common divisor" of the paths affected, to use a math term. Most of the time the commands will only affect one directory so it's obvious where they should be given, but URL rewriting affects two directories. Kinda.
The two directories you care about here are /New York (which doesn't exist) and /City (which does). The first is located at (root) -> New York, the second at (root) -> City.
The most those two have in common is the (root) part. So I say that the rewrite rules should be placed in an .htaccess file at (root).
If you were changing /browse/city/New York (doesn't exist) into /browse/city/City/ (does exist) then I'd put the rules in /browse/city/.htaccess - but you could do it in any parent folder of it: /browse/.htaccess or /.htaccess.
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 1:42 am
by kalpesh
I try your code but it's not working.
It does not change the url.
I include .htaccess in root,City, root/include and City/include.
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 1:46 am
by requinix
Works fine for me. It goes in the root, by the way.
"Not working" could mean a lot of things. Do you have mod_rewrite enabled? Did you include a RewriteEngine directive? What else is in the .htaccess?
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 2:13 am
by kalpesh
It still not working
I also include Rewrite engine.
The Code in .htaccess is:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)(/index.php)? /City/City_Index.php?City=$1 [QSA]
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 5:01 am
by requinix
kalpesh wrote:It still not working
Well yeah, I didn't tell you do to anything.
Check that the htaccess is even being processed. Make an error in it (like make a typo, or put in something that's not valid) and see that you get a 500 error when accessing anything.
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 5:30 am
by kalpesh
No error is thrown.
when i change code in .htaccess is:
Options +FollowSylinks
RewriteEngine on
RewriteCond %{REQUEST_FILAME} !-f typo
RewriteCond %{REQUEST_FILNAME} !-d
RewriteRule ^/?([^/]+)(/indx.php)? /City/City_Idex.php?City=$1 [QA]
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 5:41 am
by requinix
By default Apache doesn't let you use htaccess files on your own. They're disabled.
Take a look at the server's .conf files for where your website is defined. I can't really help you with that part.
Once you find the definition (it will include stuff like a ServerName and a DocumentRoot) add an "AllowOverride All" to the <Directory>.
As an example, here's the configuration for my local (testing) server:
Code: Select all
ServerAdmin ***
DocumentRoot "***"
ServerName ***
<Directory "***">
[color=blue]AllowOverride All[/color]
Order Deny,Allow
</Directory>
Re: Url rewriting problem
Posted: Tue Dec 30, 2008 6:48 am
by kalpesh
I try to change config file which is in apache server.
But It still not work .
But what i find there is this:
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>