Htaccess is not my favourite and please be kind enough to help me with this.
Ex. Www.domain.com/about.php shows the site with styles rightly. In the browser if add www.domain.com/about.php/ or www.domain.com/about.php\ all the styles are ruined and page is distorted.
How to eradicate backslash and slash after file extension in htaccess.
Appreciate your help
Rgds
It is path/to/style.css but when you add / after about.php , the included file path will be changed to about.php/path/to/style.css so nothing will show up.
To solve this issue add this <base href="/"> between <head> Tags in order to keep a base fixed :
<head>
<base href="/">
</head>
Update:
As per your comment that you want to add rules in .htaccess for this case , try this :
RewriteEngine On
RewriteRule ^(.+)\.php/(.*)(\.css)$ $2$3 [L]
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 want to be able to Rewrite a following url:
www.mysite.com/en/contact
to something like this
www.mysite.com?l=en&p=contact
but keep the structure.
I tried the following RewriteRule:
RewriteEngine On
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?l=$1&p=$2 [L]
but the browser then wants to load all the included scripts like the css from
www.mysite.com/en
How can I tell the browser, that it shouldn't follow the url link?
Or something like that
Thank you for your help
Chris
There are 2 methods to solve this:
1) Use base tag inside head tag
<base href='/'>
2)Use relative links
<link rel='stylesheet' href='/css/style.css'>
Here the browser looks for the CSS file in the folder in the root named CSS, whatever the URL request may be.
His friends, currently my website is set up in the "beta" folder in my root just like
www.example.com/beta
Now if any user enters the following URL
www.example.com
then he should be automatically redirected to the first URL, any ideas? I know this can be done through .htaccess but i am not sure about it :( help me please. thanks
You'll find a good example of what you want right up at the top of When Not To Use Rewrite, which is a page everyone should read before they edit one character of an .htaccess file.
RewriteRule ^/(.*) http://other.example.com/$1
# is better expressed as..
Redirect / http://other.example.com/
Or, in your case,
Redirect / /beta/
Try adding
Redirect 301 / http://www.example.com/beta
to your .htaccess file in the root directory (untested)
Actually you can do it pretty simple (no .htaccess modification required).
Edit the headers of index.html file from your server main director (/).
Within the <HEAD> ... </HEAD> section add your redirection code, for example:
<meta http-equiv="refresh" content="0;URL=http://www.example.com/beta/somepage.html" />
Note that this should be located inside index.html of you main dir /.
For references see: http://devmain.blogspot.co.uk/2013/06/html-auto-redirect-website-to-different.html
Hope it help.
I need some simple help with my htaccess file, thank you in advance.
I have a number website URLs, such as:
www.site.com/index.php?page_path=solutions-overview.html
www.site.com/index.php?page_path=solutions-a.html
I want to use the RewriteEngine to change the above links to the following respectively:
www.site.com/solutions/overview
www.site.com/solutions/a
Below is the .htaccess code I am using:
RewriteEngine On
RewriteRule ^solutions/overview index.php?page_path=solutions-overview.html
RewriteRule ^solutions/a index.php?page_path=solutions-a.html
This works, however all of my images, CSS files and JS files no longer load because the page is trying to fetch the wrong URLs. For example "/images/blah.jpg" is instead loading as "/solutions/images/blah.jpg".
How can I modify the htaccess code to prevent relative URLs from changing?
Thank you!
Add this line <BASE href="http://www.yoursitename.com/"> to your page inside the <head> tag as follows:
<head>
<title>Your site title</title>
<BASE href="http://www.yoursitename.com/">
....
</head>
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="/" />