Chetana
Chetana

Reputation:

.htaccess/mod_rewrite

Actually I want to run ~name/how instead of ~name/how.php.

I have made following changes in .htaccess:

# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_fileNAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_fileNAME} !-f
# then add .html to get the actual filename
RewriteRule (.*) $1.php [L]

But it will run as:

~name/~name/how

And at every link click it will be added ~name in the URL ex. http://ip/~name/~name/~name/serach.

Can you tell me what is wrong in .htaccess?

Upvotes: 0

Views: 642

Answers (2)

Gumbo
Gumbo

Reputation: 655169

This is an URL resolving issue: Relative URLs are always resolved on a base URL that is the URL of the current resource if not other stated. So if you’re on /~name/foo and there’s a link pointing to ~name/bar (this is just a relative URL path!), it gets resolved to /~name/~name/bar. But if you would point to /~name/bar, it wouldn’t get resolved as it already is an absolute URL path.

So you can avoid that by either using absolute URL paths (those begin with a /) or by changing the base URL (see BASE HTML element). But the latter will affect any relative URL reference and not just those beginning with relative URL path.

Upvotes: 0

SpliFF
SpliFF

Reputation: 38956

You are using relative, not absolute paths. Your pages now think you are in a path ~name/. You can set <base href> in your pages.

You could possibly simplify this by using 'DirectoryIndex index.php' to map /whatever to /whatever/index.php

This may help: How to use apache's mod_rewrite rewriterule without changing relative paths

EDIT: Short answer. You should consider using absolute paths for your menus and php includes to prevent issues when you start nesting deeper. Your relative paths are only valid while you are two levels deep (ie, ~laborfa2/search/)

Frankly you links are mess so you're getting confused. I strongly recommend creating a very simple test site to get you paths organised properly. Use absolute paths and relative paths as appropriate. Remove the base href as it's just confusing you more. Once you have it running try out rewrite again keeping in mind your relative paths may need to be updated if the path depth is changed by the rewrite..

Upvotes: 1

Related Questions