views:

120

answers:

2

I have transferred my website from old server to shared server.

All my code is in "lfdata/main/com" under "public_html" on the shared server.

The clean URL would look like follows:

http://ip-address/~name/how

and the rewritten URL should be:

http://ip-address/~name/lfdata/main/com/how.php

So can anyone suggest a rewrite rule for creating above URL?

A: 

this will do your rewrite including query string params

RewriteRule ^~name/how(.*)$ ~name/lfdata/main/com/how.php$1
Luke Schafer
The query cannot be matched with the RewriteRule directive. That’s only possible with the RewriteCond directive.
Gumbo
+2  A: 

Try this rule:

RewriteCond %{REQUEST_URI} !^/~[^/]+/lfdata/main/com/
RewriteRule ^(~[^/]+)/(.+) $1/lfdata/main/com/$2.php [L]

This will rewrite any request of /~name/foobar internally to /~name/lfdata/main/com/foobar.php.

Gumbo
+1. Don't forget QSA, I think this is desired as well.
Tomalak
QSA is not necessary if you don’t modify the query.
Gumbo
I have tried above but it not works?Can I paste my .htaccess file here ?
If it’s not too long, sure.
Gumbo
<FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">Order allow,deny</FilesMatch>Options -IndexesOptions +FollowSymLinks</Files>DirectoryIndex index.php<IfModule mod_php4.c></IfModule><IfModule sapi_apache2.c></IfModule><IfModule mod_php5.c></IfModule><IfModule mod_expires.c><IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_URI} !^/~[^/]+/lf/main/com/RewriteRule ^(~[^/]+)/(.+) $1/lf/main/com/$2.php [L]</IfModule>
There is a `</IfModule>` missing. But why are you using those empty `<IfModule>` blocks anyway? And why do you have mod_rewrite dependent on mod_expires?
Gumbo
actually file is too big so i removed some content .There is any way to send this file to you?? so i will describe it my problem.Can we solve it online ? If you do not mind.
Have you tried to put the mod_rewrite directives on top of the others?
Gumbo
yes I just tried but it shows "The page cannot be found" error
Try some debugging. Take a look into the server error log and at the logging feature of mod_rewrite (see RewriteLogLevel directive).
Gumbo
i tried RewriteCond %{REQUEST_URI} !(\.[^./]+)$RewriteCond %{REQUEST_fileNAME} !-dRewriteCond %{REQUEST_fileNAME} !-f# then add .html to get the actual filenamerewriterule (.*) lf/main/com/$1.php [L]please go through this:http://74.220.215.241/~laborfa2/ this our url and click on "How it works" and see the url in browser .it looks like "http://74.220.215.241/~laborfa2/~laborfa2/how"can you please tell me what is going wrong??
You’re probably using relative URL paths rather than absolute ones.
Gumbo
Since I have not done this coding, I am really not able to find where the actual path is writeen.in config it provides "root" => "/home/laborfa2/public_html/lf/main/","smarty" => "/home/laborfa2/public_html/lf/var/smarty/",
Is that where we should provide? I think they are absolute now,,...any other place we need to make the change?