I have this link formats on my webpage:
https://mypage.com/index2.php?page=registration
https://mypage.com/index2.php?page=food&category=1
The first type is replaced as this:
https://mypage.com/registration (works well)
And I would like to format the second as:
https://mypage.com/food/1 (doesn't work, the page is loaded, but the images don't)
So I created the following htaccess file:
RewriteEngine on
RewriteRule ^$ index.php [L]
RewriteRule ^([^/.]+)?$ index2.php?page=$1 [L]
RewriteRule ^food/([^/.]+)?$ index2.php?page=food&category=$1 [L]
But doesn't work. :(
What is wrong with this? And where are the pictures?
Thank you for your answer.
(doesn't work, the page is loaded, but the images don't)
Probably because your links are relative (doesn't begin with a /) and when you have that extra slash after /food, it changes the URL base (tries to access images in a non-existent /food/ directory). Change all your links to absolute URLs or add a base in the page header:
<base href="/" />
Related
what I'm trying to achieve is
domain.com/register/free
that would be
domain.com/register.php?type=free
When I go go domain.com/register the page loads fine, but if I put the next /free part it cant find the css or js images etc. Not too sure where I have gone wrong but this is my .htaccess file:
RewriteRule ^register$ register.php
RewriteRule ^register/$ register.php
RewriteRule ^register/([a-zA-Z0-9\-\_]+)$ register.php?type=$1
First, you can improve your rules
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^register/?$ register.php [L]
RewriteRule ^register/([a-zA-Z0-9_-]+)$ register.php?type=$1 [L]
Then, since you create a virtual folder because of your rule (/register/) and you're using relative paths (instead of absolute paths), your links are not good anymore.
Two options (both using absolute paths):
add a leading slash for all your css (and js, img, etc) links.
e.g: href="/css/style.css" instead of href="css/style.css"
add this tag just after <head> in all your concerned pages: <base href="/"> (this will avoid you to replace each link one by one)
Below is the htaccess scripti am using:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^gecko/([^/]*)$ gecko.php?gecko=$1 [L]
Which changes http://localhost/geckology/gecko.php?gecko=Zilly (which loads css etc fine) to http://localhost/geckology/gecko/zilly which doesn't load the css etc fine as it looking in directories like this http://localhost/geckology/gecko/css/theme.css when it should be http://localhost/geckology/css/theme.css
The site is huge, so if possible i would like a htaccess way of fixing this, however i will change everything to absolute urls if it's not possible
You can fix the relative URI base by simply adding this to the header of your pages:
<base href="/" />
or if you have to use htaccess, which is really inefficient and will assume all of your css/scripts/etc are all in one place, while at the same time making the rest of the world think the same thing is actually 2 different URLs:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^gecko/(css|images|other)(/.*)$ /$1/$2 [L]
This blindly rewrites any URL that tries to access "css", "image" or "other" folders within the /gecko/ path.
I'd like to redirect all outside visitors to a holding page whilst allowing all internal users to see the whole site.
I have the following
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.1.1.1
RewriteCond %{REQUEST_URI} !/holding-page/index.php$
RewriteRule .* /holding-page/index.php [R=302,L]
Which does what I want but the holding page won't pull through any styling or images.
Does anyone know who I'd achieve this?
That is due to the use of relative links on your holding page.
Insert one more rule to fix that:
RewriteRule ^holding/(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [L,NC,R=301]
If that doesn't fix the problem you can adapt these:
use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.
You can add this in your page's HTML header: <base href="/" />
I managed to resolve by allowing access to the /holding-page/ directory with the following rule
RewriteCond %{REQUEST_URI} !/holding-page/
I have this code for the htaccess file, and soon I'll have pages where I'd like to create a url like the bottom one
RewriteEngine On
RewriteRule ^Index/?$ index.php [NC]
RewriteRule ^Gallery/?$ gallery.php [NC]
RewriteRule ^Showreel/?$ showreel.php [NC]
RewriteRule ^Music/?$ music.php [NC]
RewriteRule ^Gallery/Render/?$ contact.php [NC]
If I go to the contact page, it'll display a page, but it's entirely white and only contains the text. I'm guessing it's to do with the images not being linked up properly with the new url, but how would I actually go about fixing this without having to manually edit the locations of each image?
You can try adding this in your page's header:
<base href="/" />
or change all of your links to absolute URLs. This issue is most likely that your links are all relative, and when you try to request a URL like:
http://yourdomain.com/Gallery/Render
The relative URI base becomes /Gallery/ instead of / (which is what it is if you access /contact.php directly). And when the browser tries to resolve all the relative links on the page, it uses the wrong URI base.
Hi I have a basic .htaccess file in a subdirectory folder called 'support' which looks like this:
RewriteEngine on
RewriteRule ^knowledgebase/([^/]*) knowledgebase.php?article=$1 [NC,L]
RewriteRule ^knowledgebase/category/([^/]*) knowledgebase.php?category=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I have changed the links in my files and removed the .php extension. When I click on a link to the rewritten url to my knowledgebase file everything works fine however I then have further links to the same file with query strings in the url eg:
$link = 'knowledgebase/category/'.$article['catid'];
The problem is once I am on the knowledgebase page links appear as:
http://www.example.com/support/knowledgebase/knowledgebase/category/2
I am pretty sure I need to use a RewriteCond to stop it rewriting but I can't figure out exactly what is required.
Any help would be appreciated.
If I understand correctly, I think this is not a mod_rewrite problem, since mod_rewrite has nothing to do with what links display on the page. Rather, this looks like an issue with the hrefs that are actually in your link definitions (i.e., <a> tags).
The quickest fix might be to add something like:
<base href="http://www.example.com/support/" />
within the <head> section of your pages. That way, if "knowledgebase" is specified within the links, it won't show up twice in the URL for that link.
Let me know if I have this completely wrong.