RewriteRule for subfolder htaccess - php

My url blog is here http://localhost/tibiaservers_11.10.19/blog
And my posts should be working like the following. after blog/
http://localhost/tibiaservers_11.10.19/blog/marketing-tools
http://localhost/tibiaservers_11.10.19/blog/the-cyber-house-rules
why isn't it working?
here is htaccess
Options +FollowSymLinks
RewriteEngine On
# FOR LOCALHOST RewriteBase /tibiaservers_11.10.19/
# FOR PRODUCTION RewriteBase /
RewriteBase /tibiaservers_11.10.19/
DirectoryIndex index.php
# przekierowanie na bez www
#RewriteCond %{HTTP_HOST} ^www\.tibiaservers\.net$
#RewriteRule ^/?$ "http\:\/\/tibiaservers\.net\/" [R=301,L]
<IfModule mod_rewrite.c>
# For Blog
RewriteRule ^blog/t-(.*)$ tagpost.php?id=$1 [L]
RewriteRule ^blog/c-(.*)$ catpost.php?id=$1 [L]
RewriteRule ^blog/a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
# RewriteCond %{REQUEST_FILENAME} !-d [NC]
# RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^blog/(.*)$ viewpost.php?id=$1 [QSA,L]
##### - blog end

I think your RewriteRule should start with: ^tibiaservers_11.10.19/
This:
RewriteRule ^tibiaservers_11.10.19/blog/t\-(.*)$ tagpost.php?id=$1 [L]
Would match this url:
http://localhost/tibiaservers_11.10.19/blog/t-asdf
I use this tool for testing my .htaccess rules: htaccess.madewithlove.be

Related

Rewrite URL Htaccess

I want redirect augias.eu to subdirectory augias.eu/fr.
Redirection is working fine but all the urls like augias.eu/fr/path are redirected to augias.eu/fr
I don't get it. The website is live.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^augias.eu [NC,OR]
RewriteCond %{HTTP_HOST} ^www.augias.eu [NC]
RewriteRule ^(.*)$ https://augias.eu/fr/$1 [L,R=301,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
HTacces file of the /fr directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
In the main directory .htaccess file change this RewriteRule:
RewriteRule ^(.*)$ https://augias.eu/fr/ [L,R=301,NC]
to this one:
RewriteRule ^(.*)$ https://augias.eu/fr/$1 [L,R=301,NC]
because $1 represents the first value enclosed in (). In this case match this expression (.*).
And inside the /fr/ folder, edit or create a new .htaccess file with this content:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /fr/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /fr/index.php [L]
</IfModule>
# END WordPress

Redirect sub-domain all post to main domain

I want to redirect all posts that are on subdomain to live domain.
For example, www.blog.mydomain1.com/post-1 to www.mydomain1.com/post-1
I try this htaccess code , It redirect the main subdomain but it does not redirect the post links
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain1\.com$ [NC]
RewriteRule ^(.*) http://www.mydomain1.com/$1 [R=301,L]
My Complete HTAccess is
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [NC,R,L]
# BEGIN MainWP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/plugins/mainwp-child/(.*)$ /wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST [QSA,L]
</IfModule>
# END MainWP
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [NC,R,L]
Clear your browser cache before testing this Redirect.

Redirect from old domain to new domain not work

I try to Redirect from old domain to new domain, By below code, but not work, Where is error.
# 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]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
</IfModule>
# END WordPress
You need to place redirect rule before WP catch-all rule otherwise you will only get index.php after redirect on new domain:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Load another domain images to my domain using htaccess?

I have 2 domains and 2 servers example.com and example2.com. for eg: example.com is my main domain. i upload my site images into example2.com
my current image path http://example.com/data/photos/sample.jpg.
but my all images are in http://example2.com/data/photos/sample.jpg
So i create htaccess 301 redirect
RewriteEngine on
RewriteBase /
RewriteRule ^data/photos/(.*)$ http://example2.com/data/photos/$1 [R=301]
But its not working for me. Because of i called full URL into my all pages. so any one suggestion its very helpful for me
Updated my old Htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteEngine On
RewriteBase /
RewriteRule ^data/photos/(.*)$ http://example2/data/photos/$1 [R=301]
</IfModule>
You need to reorder your rules. Your final htaccess should look something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(data/photos/.*)$ http://example2.com/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
change it with this
RedirectMatch 301 ^/data/photo/ http://example2.com/data/photo/
to create a 301 for the entire directory.

Symfony 2 Redirect to url without www

I don't know how to redirect my symfony application from:
http://www.mysymfonyapp.com
to:
http://mysymfonyapp.com
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
If I'm entering application without 'www' it works, but with 'www' it has redirects loop. I've tried asking google, but I didn't find anything.
Ok, I figured it out and answering for others.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteBase /mysymfonyapp.com/web/ (you don't need declare RewriteBase if you have this code in mysymfonyapp/web/.htaccess)
RewriteRule ^(.*)$ app.php [QSA,L] #Remember to redirect app.php
</IfModule>

Categories