I have a static html home page.
I have a joomla installation at /blog/
I have a sub-blog at /blog/my-sub-blog
I want to it to show up in the browser as just /my-sub-blog
So I use this
RewriteEngine On
RewriteRule ^my-sub-blog/?$ /blog/my-sub-blog/ [NC]
And the result is an "article not found" 404 in joomla.
If i add the redirect flag just for testing, it redirects just fine and works
RewriteEngine On
RewriteRule ^my-sub-blog/?$ /blog/my-sub-blog/ [NC,R]
But I want it to invisibly rewrite, not redirect.
Any suggestions on how to get it to silently rewrite?
It's possible that joomla is looking at the REQUEST_URI and similar server variables which would show up as something different because the request is actually /my-sub-blog/ and not /blog/my-sub-blog/ like it's expecting. The easiest way to get around this is to have mod_proxy loaded, and internally proxy the request instead of redirecting the browser:
RewriteEngine On
RewriteRule ^my-sub-blog/?$ /blog/my-sub-blog/ [NC,P,L]
or better yet:
RewriteEngine On
RewriteRule ^my-sub-blog/?(.*)$ /blog/my-sub-blog/$1 [NC,P,L]
Related
I have a url which is
www.domain.com/index.php?route=ticketsystem/generatetickets
I want people who type in the url www.domain.com/contact to be redirected to the page index.php?route=ticketsystem/generatetickets however have the url bar still show /contact is that possible via htaccess and if so how? I tried the below
RewriteEngine On
RewriteBase /
RewriteRule contact /index.php?route=ticketsystem/generatetickets [L,QSA]
For your shown attempts, please try following .htaccess rules file. Make sure your index.php and .htaccess files are present in same directory/folder. Also better to use & rather than using / for query string.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^contact/?$ index.php?route=ticketsystem&generatetickets [QSA,NC,L]
I have a Joomla site with .htaccess URL rewrite. So in Google my links appear as:
DOMAIN/abc ...
Now probably the rewrite mod on the hosting stopped working and I need to redirect all people from Google to link such as:
DOMAIN/index.php/abc ...
I tried this
RewriteEngine On
RewriteRule ^(.*)$ https://example.com/index.php/$1 [R=301,L]
but it doesn't work.
You should exclude the request start with index to avoid looping so , change the rules as follow:
RewriteEngine On
RewriteRule !^index\.php https://example.com/index.php%{REQUEST_URI} [R=301,L]
Note: clear browser cache
I want my website to redirect from https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id to https://www.sitename.com/single-product and want the same original URL restored.
Currently, https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id URL gets me to 404
I know I will have to use the P flag in .htaccess file in document root to get this working. But I don't know why my solution is not working
RewriteCond %{REQUEST_URI} ^/single-product
RewriteRule ^(.*)$ /single-product/$1 [P]
I have found a solution not it is not working on my server. I guess mod_proxy is currently off on my server
RewriteEngine on
RewriteRule single-product/* https://www.sitename.com/single-product/ [P]
This is a great website to test these scripts
https://htaccess.madewithlove.be/
Trying to ask my question again and explain it the best I can.
I am running WAMP on windows 10. Apache version 2.4.18. My project is in www folder named hoidja.ee. mod_rewrite is enabled, AllowOverrideis set to All.
Inside that folder I have .htaccess file, where I am trying to accomplish rewrite without redirect and it does not work at all. I know the .htaccess file is working, since I can rewrite index.php to /home/ for example and it is working perfectly fine.
I have a page with all the users listing. You can click on the user, and it will take you to a url:
http://localhost/Hoidja.ee/hoidja.php?user_id=94&username=John
How I would like this to show is
http://localhost/Hoidja.ee/user/John
without any redirection.
What I have tried:
#tried first with only user_id
RewriteCond %{QUERY_STRING} ^user_id=([A-Za-z0-9-]+)$
RewriteRule ^hoidja\.php$ /user/%1? [L]
This gave me 404 that /user/94 doesn't exist.
RewriteRule ^user/([0-9]+)/([A-Za-z0-9-]+)/?$ hoidja.php?user_id=$1&username=$2 [QSA]
This doesn't do anything visually. If I enter http://localhost/Hoidja.ee/user/94/John in the url manually, it goes to that page and shows the user data, but if I enter the original url it does not rewrite it. I am using <base> as well.
I have tried all the possible ways but nothing seems to work. How can I accomplish the url rewrite?
You are getting the 404 error because you are rewriting to a non-existent path /user/94 .you will need to redirect /hoidja.php?user_id= to /user/94 and then rewrite /user/94 back to the real location.
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^user_id=([A-Za-z0-9-]+)$
RewriteRule hoidja\.php$ /hoidja.ee/user/%1? [L,R]
RewriteRule ^(?:hoidja\.ee/)?user/(.+)$ /hoidja.ee/hoidja.php?user_id=$1 [L]
I have a page which I'm redirecting using PHP:
header('Location:notices.php');
exit;
Is it possible to hide the page name entirely using .htacess? So instead of the browser showing the URL http://example.com/notices.php, it instead shows http://example.com but in effect it really loadedhttp://example.com/notices.php.
I'm open to any other solution since my goal here is just to not show the actual page being loaded.
EDIT: The browser still loads notices.php (not /index.php) but the URL shows /. Only the URL changes, or in this case, masks the file being loaded.
notices.php:
<?php
include('index.php');
exit();
doing a header() redirect WILL show the new url in the browser. That's unavoidable. You've told the browser "go over there", so it obediently does.
The other option is to use mod_rewrite to silently rewrite requests for /notices.php into a request for /index.php.
Add the following to your .htaccess file in the root folder of example.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)?\.example.com [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule . notices.php [L]
All requests to example.com will show notices.php, if this is what you really want.