I want to redirect to my post URL when someone visits subdomain of that post name on my site.
Like this
https://www.example.com/sub/mypost ---------> https://mypost.example.com
The site is running on Apache server
So have tried some changes to a .htaccess file
Please not everything is SSL
RewriteEngine on
RewriteCond %{HTTP_HOST} https://$1.example.com [NC]
RewriteRule ^(.*)$ "https://www.example.com/sub/$1" [L,P]
It did not seem working. it redirects to Site cant be reached message on browser.
This is my previos htaccess file before changes.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank You.
Related
I have uploaded my Laravel project on Infinityfree free hosting.
My url is like this: http://abc.freecluster.eu/
But it shows ERR_TOO_MANY_REDIRECTS
I have added below code in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://abc.freecluster.eu/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Check that your routes don't have the same name, otherwise they will just redirect you to each other causing this error. This post might be relevant.
Hope you guys are well, I have faced a problem deploying my laravel project on Cpanel. When I am hit my route URL or a root URL then it show me "404 not found"
This is the root url : https://laravel.tamimikbal.com/project1/
I have written this code on my root .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
And this the public/.htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The .htaccess is not redirecting properly to the public directory. I can access and navigate on your site using "https://laravel.tamimikbal.com/project1/public/".
Try this as the contents of the .htaccess file in your root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I can better understand if you put how is the routing url should be looks like
anyway you can try this code:
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
while you don't have www. and https is activated on your domain you can use this code to make redirect from www. to none www and from http to https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
the rout request and file directory you can use this code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css|webp|JP2)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
if you want to redirect you system files to 404 page edit this code and replace your system folder and your 404 routing page
RewriteRule ^system/(.*) index.php?route=your 404 page [L]
Hello my fellow developers,
i need to change my document root some specific folder which holds the source code of my laravel project on a shared hosting, since my hosting plan dont let me change default document root so i cannot change my default index so i want to have to redirect it using .htaccess
for far i have been able to internally redirect with the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ master/project/public/index.php
doing this i am able to redirect to desired folder, but for some reason it is not working for assets, i keep getting 404 on all the assets
master/project/public/css/[all styles]
master/project/public/js/[all scritps]
master/project/public/images/[all pictures]
master/project/public/fonts/[all fonts]
how can i achieve this without having to change urls,
internal redirect is working but i cannot figure out why all of my assets are returning 404
Try this
i m using shared hosting and this i m using for redirect asset to public dir
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
#all request to public dir
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To redirect all request to public
#all request to public dir
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
so i found solution to my problem,
this solution is what i ended up with.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !master/project/public/
RewriteRule (.*) /master/project/public/$1 [L]
this way you can change the default root of the your hosting using .htaccess file. hopefully it is helpful for everybody new to .htaccess
I have a site which is mainly based on Code igniter.Inside that I have a store setup using opencart.Everything working fine until I try to user opencart seo friendly urls.
Once done that,it shows codeigniter 404 view.
How can I bypass CI routes when url is xyz.com/store
My Htaccess file is here :
# Customized error messages.
ErrorDocument 404 index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
The problem is likely caused in your .htaccess file. The default Codeigniter .htaccess file is set up to route all traffic to your public directories index.php. To prevent this you will need to set up a RewriteCond to exclude any directories you want to keep outside of codeigniter.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(store[^/]*)$
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
I have made a copy of a wordpress site and set it up on localhost (WAMP), everything works well apart from all of the AJAX calls as the URLs have not been updated.
I need the urls to be in the following format: http://localhost/mysite/dashboard/ but instead they have the /mysite/ part missing ie. http://localhost/dashboard/
I assumed this could be resolved by doing a 301 redirect in the same way a none www domain is redirected to a www. I have tried the below but it doesn't do anything:
RewriteCond %{HTTP_HOST} !^/mysite/\.
RewriteRule ^(.*)$ %{HTTP_HOST}/mysite/$1 [R=301,L]
---------------------HTACCESS FILE----------------------------
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite/index.php [L]
RewriteRule !^mysite/ /mysite/%{REQUEST_URI} [R=301,L,NC]
</IfModule>
# END WordPress
That rule should be:
RewriteRule !^mysite/ /mysite%{REQUEST_URI} [R=301,L,NC]
%{HTTP_HOST} variable only matches domain name in the request not the REQUEST_URI.