RewriteRule on static url - .htaccess

I'm putting online a new version of my site and i have to redirect some old indexed pages to the new ones.
So i have generated an htaccess based on static urls (the old ones redirecting to the new ones).
It work for some of them but it figure out that it make 404 errors on the ones that own get parameters (I think that's the cause).
There is 2 rules, the working one and the one that fails :
<IfModule mod_rewrite.c>
RewriteEngine on
#Working one
RewriteRule old_page_indexed.htm http://newsite.com [R=301,L]
#Not working
RewriteRule PBBios.asp?PBMInit=1 http://newsite.com [R=301,L]
</IfModule>
I've tried to following but not working :
RewriteRule PBBios.asp\?PBMInit=1 http://newsite.com
RewriteRule ^PBBios.asp\?PBMInit=1$ http://newsite.com
Do you have any idea how to do this in htaccess?
Thanks a lot =)

Test against the path and query string independently
RewriteCond %{REQUEST_URI} ^PBBios.asp$
RewriteCond %{QUERY_STRING} ^PBMInit=1$
RewriteRule ^(.*)$ http://newsite.com [R=301,L]

Related

htaccess RewriteRules Strange behavior

Soo i have this htaccess file in my subfolder for a project:
RewriteEngine On
# HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R]
RewriteRule ^homepage$ index.php [L]
RewriteRule ^news$ news.php [L]
RewriteRule ^store$ store.php [L]
RewriteRule ^staff$ teams.php?t=1 [L]
In this file "homepage" works, "news" works and "staff" too but "store" not
I had a similar problem last week but i abandoned it becouse i tried everything:
RewriteRule ^/?news/(.*)$ news.php?art=$1 [L]
Here i want a rewrite rule /news/foobar to /news.php?art=foobar
I know i maybe not understand htaccess fully but if some work why others not?
It can be usefull information i use LiteSpeed Webserver
Soo this is just an answer who has this same problem when you use cyberpanel/openlitespeed you need to restart lsws everytime when you modify your .htaccess only then it will work.
If you use OLS Enterprise you dont need to do this...

.htaccess two old URLs to one new

I'm rewriting a website with a larger google cache.
So my Problem is that the old links should be reachable but under a new URL.
I'm sitting since 8h to rewrite the URLs with htaccess... But it seems to be to hard for me, so how can I make this:
old htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*) https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^banana/(.*).htm$ https://example.com/banana/index.php?id=$1 [R=301,L]
Future config wish:
1. https://example.com/banana/Berlin.htm
2. https://example.com/banana/index.php?id=Berlin
both leading to --> https://example.com/banana.php?id=Berlin
working .htaccess for rewrite 1:
RewriteCond %{REQUEST_URI} ^/banana [NC]
RewriteRule /(.*) https://example.com/banana.php?id=$1 [R=301,L]
working .htaccess for rewrite 2:
RewriteRule ^(.*) https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^banana/(.*).htm$ https://example.com/banana.php?id=$1 [R=301,L]
But either I run into Too many redirects or to not working rewrites...
And when i got one config working fine the oder old URL is pointing to 404 ...
Thank you in advance and very much!

.htaccess rewriting GET

I've never needed to use a .htaccess before and I'm fairly new to coding I'm trying to get localhost/index.php?id=123456789 to be passed as localhost/123456789/ but I just cant get the HTaccess right, i've tried everything I could find from prevoius posts here, haha!
My current HTACCESS looks like this, however it doesnt do what I want.
RewriteEngine On
RewriteRule ^id/(\d+)$ /index.php?id=$1 [NC,QSA,L]
You can do it with mod_rewrite in .htaccess however I'm not sure from your question which direction you want it to be passed to.
If you want people to type the php script in the URL bar you want:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/
Or if you want people to enter the "pretty" version but for your server to load the PHP script you need:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING}
For both ways and 301 redirect to pretty URL:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING} [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/ [L,R=301]

Redirect url with .htaccess

I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]

Magento non www to www

I am pulling my hair out here.
I have created a landing page which is http://www.pps-supplements.com/samples
it works and you can access it fine - no problems.
If you type in the address bar:
pps-supplements.com/samples
it takes you to the home page which is not good and causing me to have a headache.
My website is working well for non www to www on home page and categories but not on cms pages.
I have read a few posts on here and tried their solutions which is to edit the htaccess file but it hasn't fixed it.
Does anyone have any ideas how I can resolve this issue??
Pretty please!
You could try this in your .htaccess file....
Be sure to add it above any other rewrite rules or conditions you may already have in your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.pps-supplements\.com [NC]
Rewriterule (.*) http://www.pps-supplements.com/$1 [R=301]
</IfModule>
This will redirect any domain that is not www.pps-supplements.com to the version with www's
Also very handy for using when pointing multiple domains at a site.
Also, be sure that the webserver is set-up to receive the non www version, as in that it is listening for that version, as well as for the version with www's.
For anyone else looking at the accepted answer and running into issues with it not working you may have other Rewrites in place that need to be stopped from executing.
You can stop further execution by including the "L" param.
Example:
Rewritecond %{HTTP_HOST} !^www\.domain\.com [NC]
Rewriterule (.*) http://www.domain.com/$1 [R=301,L]
I wanted to redirect from example.com/category/ to www.example.com/category/
and I found solutions:
turn off Auto-redirect to Base URL in backend
and use this code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
For Magento Multistore-Setups:
Rewritecond %{HTTP_HOST} ^example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,L]

Resources