help me to rewrite url urgent

Discuss practical ways rearrange URLs using mod_rewrite.

help me to rewrite url urgent

Postby nitin027 » Sun Dec 31, 2006 4:08 am

Hello,

i have a site name like this....
www.devtalash.com/index.php

so user from london will login then it can see this url

www.devtalash.com/london/index.php

and user from america will login then it can see this url

www.devtalash.com/america/index.php

then user can see this url , but the file will run "www.devtalash.com/index.php" means it can work for all files like index.php or 1.php or 2.php etc.. and for any directory(eg.america,inidia,london)..

is it possible ? please help me soon...
nitin027
 
Posts: 12
Joined: Sun Dec 31, 2006 3:41 am

Postby richardk » Sun Dec 31, 2006 10:31 am

So you want all requests to .php files to go to /index.php?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.+)\.php$    /index.php  [QSA,L]


Or all 404 requests?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule .  /index.php  [QSA,L]


Or just requests to .php files one directory deep?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^([^/]+/[^/]+)\.php$ /index.php [QSA,L]


Or something else?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nitin027 » Mon Jan 01, 2007 12:36 am

thank you very much sir, for your reply...

but i want that user can enter any directory name

and any file name inplace of "kent " and "index.php"...

mod_rewrite can work for all file and folders
eg....
when user write...
www.mywebsite.com/kent/index.php
then it code will work for this...and file will www.mywebsite.com/index.php run

and when user write.. www.mywebsite.com/kent/login.php
then it will run www.mywebsite.com/kent/login.php ..

so code must be run for any file name after directory it will go to that file name in parent directory.....

also the kent folder will not exitst over there.

if possible then please reply,thanks
nitin027
 
Posts: 12
Joined: Sun Dec 31, 2006 3:41 am

Postby richardk » Mon Jan 01, 2007 7:56 am

I think you want this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^[^/]+/([^/]+\.php)$ /$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nitin027 » Mon Jan 01, 2007 11:24 pm

i am very happpy , thats its work now...

but i need some more help...

suppose user write..

www.mysite.com/kent/index.php

then it works fine.

but when user write

www.mysite.com/kent/

then it should run www.mysite.com/kent/index.php

but this is not work. if user not enter any file name then by default index.php can run....

also when runs "www.mysite.com/kent/index.php"

then images are not displaying ,the path should be

http://www.mysite.com/images/members_home1.gif

but it displays
http://www.mysite.com/kent/images/members_home1.gif




also want some more help here...

when user write www.mysite.com/kent/admin

then they can enter in to "admin" folder www.mysite.com/admin
and all files will run same from admin folder which is exists at athere

but they can see www.mysite.com/kent/admin/

also when no file name then, index.php will run....

same for
www.mysite.com/kent/partner

www.mysite.com/kent/affiliate

thanks,

nitin makvana..
nitin027
 
Posts: 12
Joined: Sun Dec 31, 2006 3:41 am

Postby richardk » Tue Jan 02, 2007 9:58 am

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+(/(.*))?$ /$2 [QSA,L]


If the images are still broken you need to use absolute paths, eg.
Code: Select all
<img src="/images/my_dog.png" alt="My dog.">
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nitin027 » Tue Jan 02, 2007 10:54 pm

I am very glad to inform u, that it is working as i want...

but i need one new in this....

presetly url written by user is

www.mysite.com/kent/index.php
and it working for everything right...

but url will like this...

www.mysite.com/kent/index.php?id=1
www.mysite.com/kent/index.php?id=2
www.mysite.com/kent/index.php?id=34

now i want that user can not see" ?id=1"
user can only see

www.mysite.com/kent/index.php


thnks you very much sir...
nitin027
 
Posts: 12
Joined: Sun Dec 31, 2006 3:41 am

Postby richardk » Wed Jan 03, 2007 8:52 am

The variable can't just disappear, you can make it look nicer though, maybe /kent/1/, with:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/[^/]+/([0-9]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%1 !-f
RewriteCond %{DOCUMENT_ROOT}/%1 !-d
RewriteRule ^[^/]+/[0-9]+/?$ /index.php?id=%1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+(/(.*))?$ /$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nitin027 » Fri Jan 05, 2007 8:49 am

Hello sir,
i tried your code, but it is priting some url on screen...but now no problem the requirement has been changed,
now if , the url is www.mysite.com/kent?id=1 then no problem....

so now i will use this code.
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+(/(.*))?$ /$2 [QSA,L]

but now i need to resolve this problem..

the url is looklike this..." www.mysite.com/York%20Shire?id=1"

i want to remove "%20" from url...

Url will look like this. " www.mysite.com/YorkShire?id=1 " means "%20" will removed from there.
also if this is not possible, then please do it " www.mysite.com/York-Shire?id=1 " but my first priority is " www.mysite.com/YorkShire?id=1 "
nitin027
 
Posts: 12
Joined: Sun Dec 31, 2006 3:41 am

Postby richardk » Fri Jan 05, 2007 2:28 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*)(\+|\ |%20)(.*)$ /$1$3 [E=U:/$1$3]
RewriteCond %{ENV:U} !^(.*(\ |%20).*)?$
RewriteRule .* %{ENV:U} [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+(/(.*))?$ /$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 2 guests

cron