In my .htaccess folder I'm using RewriteRule to forward music.php?artist=name to music/name. My problem is, if you click another link, instead of going to site.com/music/otherartist, it goes to site.com/music/name/otherartist (you're still stuck in the "music/name" directory). I've tried adding
RewriteBase /
and I get the error "Object not found." I'm sure the solution to this is really simple, but I haven't figured it out yet. :/
You need to change your links to be absolute URLs or add a relative URI base to the header of your pages:
<base href="/" />
Related
I am new to .htaccess
I have created many links which open up pages based on a search result.
The link addresses are, each link has a different prid such as 3110, 3111, 3222
http://mywebsite.com/prid-3110/1500-Sq-Ft-Residential-Plot-for-Sale-In-Arya-Shine-City-Irba-Ranchi-For-Rs-9.75-Lakh
I want this link to point to (ignore everything after the second slash)
http://mywebsite.com/prid-3110/
My Current .htaccess rule is
RewriteRule ^prid-([0-9]+)$ views/propertyview.php?property_id=$1
The correct answer is working below
And add this the following so everything else like CSS, Images work because your browser will know from where to start looking for files.
<head> <base href="../"> </head>
You can use:
RewriteRule ^prid-(\d+)(?:/|$) views/propertyview.php?property_id=$1 [NC,L]
With (?:/|$) you avoid prid-3110blabla, but you can use only:
RewriteRule ^prid-(\d+) views/propertyview.php?property_id=$1 [NC,L]
without this test.
I have tried this every which way I could, but am not getting any love. I am attempting to redirect a subfolder in the site to just a static page. But I do NOT want to redirect anything ELSE that is inside said folder.
I have tried using the regular redirect 301, but of course that redirects everything in the subfolder.
To sum up: I want to redirect http://www.domain.com/folder/ to http://www.domain.com/foldername2/file.php without redirecting anything else inside /folder/.
The following is what I have in my htaccess... but... it is just ignoring it completely.
RedirectMatch 301 ^/folder$ http://www.domain.com/foldername2/file.php
Thanks in advance for help.
Instead of relying on HTTP, you can use a nearly empty index.html file which contains a <meta> refresh tag in the head section of the document.
The wikipedia article on meta refresh has some good examples, e.g.
<meta http-equiv="refresh" content="0; url=http://example.com/">
The 0 means "zero seconds"—that is, immediately.
After much struggling, I found the answer! It does not use the RedirectMatch, however. It uses a rewrite condition and rule instead.
RewriteCond %{REQUEST_URI} ^/folder/$
Rewriterule ^(.*)$ http://www.domain.com/foldername2/file.php [L,R=301]
Could you help me with this htaccess problem of mine?
My URL is:
mysite.com/blog.php?post=01/01/2012/my-first-post
And I want to transform it into this:
mysite.com/post/01/01/2012/my-first-post/
Which I partially solve this by using this:
RewriteRule ^post/([A-Za-z0-9-]+)/?$ blog.php?postd=$1 [NC,L]
Now here comes the problem. When I try to click the second post "01/01/2012/my-second-post" which was suppose to go to
mysite.com/post/01/01/2012/my-second-post
but in return it goes to
mysite.com/post/01/01/2012/my-first-post/01/01/2012/my-second-post
Try adding in the header of all your pages:
<base href="/">
i am using the rewrite rules in htaccess but i am getting error on site,
while adding a / (slash) into the link
My Example Code:
RewriteEngine On
RewriteRule ^categories/(.*)$ ?act=directory&category=$1 [L]
actually i want to call this link from the category listing where the href link is
categories/category-name
now if i call this link like this
categories-category-name
then it works fine, but if i add the slash then the site looks as it doesnt have the css :(
only unstyled text i can see.
Thanks In Advance
Please Advise.
You need to add a slash in your css path
href="/css/your_style_name.css"
This will work
I have a couple of sites that are currently under development and I've put them under a specific subfolder for clients/co-workers to view - "http://dev.staffanestberg.com/site-name/". I've run into some problems getting the sites working with .htaccess. I can reach the index page by typing in the url for a site folder but neither img/style/js/etc linking or page rewriting works. Looking for a solution to this, Apache's "RewriteBase" seems to be the most likely one, however I can't get it to work.
Tried
RewriteBase http://dev.staffanestberg.com/site-name/
RewriteBase /site-name
What would be the correct method?
Thanks in advance,
-Staffan
mod_rewrite’s RewriteBase directive does only apply to rewrites using RewriteRule. And that does only apply for requests that are sent to the server.
But if the requested URIs are already wrong, RewriteBase doesn’t do any help. What you could try instead is the HTML element BASE that set’s the base URI for the current document.